added tile node replacing, position changes but doesn't change visible ingame

This commit is contained in:
2022-11-15 20:01:28 +01:00
parent 9138545028
commit 36fe0f1f08
2 changed files with 17 additions and 2 deletions

View File

@@ -11,15 +11,22 @@ public class tilemap_foreground : TileMap
public override void _Ready()
{
ReplaceStaticTiles(1);
ReplaceStaticTiles(1, "debug_tile_one");
}
public void ReplaceStaticTiles(int CellID)
public void ReplaceStaticTiles(int CellID, string sceneName)
{
Vector2[] allCells = GetUsedCellsById(CellID).OfType<Vector2>().ToArray();
for(int i = 0; i < allCells.Length; i++)
{
GD.Print(allCells[i]);
SetCell((int)allCells[i].x, (int)allCells[i].y, -1);
var scene = GD.Load<PackedScene>("res://scenes/interactable_tiles/" + sceneName + ".tscn");
var instance = scene.Instance();
AddChild(instance);
var node = GetNode<Node2D>(instance.GetPath());
node.Position = allCells[i]; //position changes but doesn't change visible ingame
GD.Print(node);
}
}
}