SupaLidlGame/Extensions/Node2DExtensions.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2022-11-27 19:37:16 -08:00
using Godot;
2023-06-13 02:55:30 -07:00
using GodotUtilities;
2022-11-27 19:37:16 -08:00
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.Extensions;
public static class Node2DExtensions
2022-11-27 19:37:16 -08:00
{
2023-06-03 18:21:46 -07:00
public static void RayCast(this Node2D node, Vector2 ray)
2022-11-27 19:37:16 -08:00
{
2023-06-03 18:21:46 -07:00
//var spaceState = node.GetWorld2d().DirectSpaceState;
//var result = spaceState.IntersectRay();
2022-11-27 19:37:16 -08:00
}
2023-06-13 02:55:30 -07:00
public static Node CloneOnWorld(this Node2D node)
{
return CloneOnWorld<Node2D>(node);
}
public static T CloneOnWorld<T>(this Node2D node) where T : Node2D
{
var world = node.GetAncestor<Scenes.Map>();
if (world is null)
{
throw new System.NullReferenceException("World does not exist");
}
//var parent = new Node2D();
//world.AddChild(parent);
//parent.GlobalPosition = node.GlobalPosition;
var clone = node.Duplicate() as T;
world.AddChild(clone);
clone.GlobalPosition = node.GlobalPosition;
2023-07-23 23:39:20 -07:00
GD.Print("clone on world: " + clone.GlobalPosition);
2023-06-13 02:55:30 -07:00
return clone;
}
public static Node AtPosition(this Node2D node, Vector2 position)
{
node.GlobalPosition = position;
return node;
}
2022-11-27 19:37:16 -08:00
}