How do I stack TileMaps and swap them on demand?

i see, but there’s no need to save every tile’s tileset source id, etc for a single level

technically, if you are experienced enough with leveling, it can, you will need to make level editor and have a level reader for it and just make it so that each stair specifically trigger either up or down level/floor. with this it only need a single tilemap for entire 50 floors
but what i meant to show just now was how do you do that for 50 scenes of tilemap

wait dont tell me the enemy is painted with tilemap? then dont
just make a sprite2d/animatedsprite2d and spawn it on specific coords. with that you can freely set its animation and movement

use this map_to_local function to get the exact tilemap’s cell’s position to where the enemy will spawn at

Bruh watch the video, this whole game is about routing, none of the enemy ever changes position, all they have is their stats and 2 frame cycle animation
If I’m not dealing with this level of predictability I wouldn’t try so hard on automation

ok, then it will be much simpler than i thought you will add
back to your game design what is your plan to interact with the enemy that’s spawned?

I have a raycast on player, and all the enemies are an Area2D inherited class, if the raycast report an enemy it goes into auto battle
That part is fully functional no problem, I just need the dead to stay dead after changing levels

with it being painted to a tilemap so the enemy/item has their own layer than the floor/wall, then because it’s drawn first in tilemap, you will need specifically set_cell it to nothing, thing is when the enemy died, how the game knows who’s dead? from that you can get its cell’s coordinate (by knowing who’s dead and what coords the player last interacted with), and add it into the array
so when player enter the same floor, it will delete anything that’s in this array by set_cell

That’s my current plan, I just need to find a way other than making an huge array containing 50+ levels…probably dictionary once I figure out why I couldn’t assign value to it, gotta sleep now it’s 1:30 am here

basically just append Vector2() of the enemy location to array, so it will never be a long list of array
also use dictionary to contain lots of array
so it looks like the dictionary has 50 key and value
but early on all the value is empty array []
so you can imagine it like this dict={1:[],2:[],3:[],4:[],...,50:[]}
you just need to append the Vector2 Coordinate for specific key value according to the level number

levels_data[child.name] = levels_tilemap_data.duplicate()
I just figured out I had to duplicate the data since it’s just holding the reference to the array.
This should cover everything? I’ll post something as solution once it’s done.

Note: I tried overwrite old TileMap data with current one before level transition, and it turns out even if the instanced scene tile is queue_free()ed, it’s still in the TileMap, so simply read back from the scene doesn’t work, spooky ghost data comes back to life

Note 2: Apparently at some point I saved the individual tilemap as scene for experiment and forgot to change it back…now I have tons of tests to redo

Oh my god. I just figured the easiest way out. It was the thing I said in the beginning.

Just put them out of the frame.

Why did I stuck on the idea of “One giant tilemap” and never revisit the thought again?
Just stack them outside the frame, and pull the needed one onto the screen!!

signal level_changed(ascend: bool)
const NEW_MEXICO_DESERT:= Vector2(640, 0)
var levels: Dictionary

@export var current_level: int = 0:
	set(new_level):
		var has_level: bool = false
		for level: String in levels:
			if level == str(new_level):
				has_level = true
				break
		if has_level:
			levels[str(current_level)].position = NEW_MEXICO_DESERT
			level_changed.emit(new_level > current_level)
			levels[str(new_level)].position = Vector2.ZERO
			current_level = new_level

func _ready() -> void:
	for child: Node in get_children():
		if child is TileMap:
			levels[child.name] = child
			child.position = NEW_MEXICO_DESERT
	levels[str(current_level)].position = Vector2.ZERO

Goodbye, tile data array. You will not be missed, out of the frame TileMap is my friend now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.