New player add method

This commit is contained in:
Marco 2025-01-22 11:35:37 +01:00
commit a235183c61
8 changed files with 116 additions and 58 deletions

View file

@ -5,6 +5,11 @@ namespace Cirno.Scripts;
public static class Tools
{
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
{
return CreateChild<T>(node, prefab, node.Position);
}
public static T CreateChild<T>(this Node2D node, PackedScene prefab, Vector2 position) where T : Node2D
{
if (prefab == null) return null;
var newInstance = prefab.Instantiate<T>();
@ -12,7 +17,7 @@ public static class Tools
// Need to use parent instead of owner because tilemap scenes have no owner
//node.Owner.CallDeferred("add_child", newInstance);
newInstance.Transform = node.GlobalTransform;
newInstance.Position = node.Position;
newInstance.Position = position;
return newInstance;
}