I'm making a system that spawns a scene with a premade room, even though the TileMap nodes contain the exact same set, they don't interact with other giving this weird sectioned feeling to them. I attempted to make a code to get them fuse into one node but it seems I may be confusing myself on how to use local/global coordinates of the cells.
Sectioned rooms image:
My idea is ask the room scene for the cells using a ID with the method get_used_cells_by_id
and then using set_cell
to add them to the TileMap
in the main scene. Any help is appreciated
func updateDungeonTileMap():
var maintileMap = $TileMap
var tileMapID:Array = [0, 1, 2]
var roomCheck:Array = $Rooms.get_children()
for i in tileMapID.size():
for o in roomCheck.size():
var roomTileMap = roomCheck[o].getTileMap()
var cells:Array = roomCheck[o].getTileMapCells(i)
for u in cells.size():
var globalCord:Vector2 = roomTileMap.to_global(cells[u])
var localCord:Vector2 = maintileMap.to_local(globalCord)
maintileMap.set_cell(localCord[0], localCord[1], i)
for i in roomCheck.size():
roomCheck[i].removeTileMap()
maintileMap.update_bitmask_region()
func getTileMapCells(id):
return $TileMap.get_used_cells_by_id(id)