Organize tiles - overlapping (DEF-1184)

imageimage
My setup is very very basic.
I couldn’t find how to place my character between two layers.
So I just made 2 tilemap overlapping with my character between them…
it’s miserable to map like that but I’m a newbie to Defold.

Is there a known and easier way to place a character between to layers (ground/hover) without actually having 2 tilemap like me. And also, fix this ugly bug by changing the layer’s Z depending on the player’s position to the tilemap.

It might be a stupid or a tough question, altho thank you very much for the time you’ll take to answer! :smiley: Happy Saint-Jean :sunny:

1 Like

Your workaround is currently the only way to get a sprite between tile layers. I believe there is an issue in our backlog for that.

Edit: yep. Tilemap layers and sprite ordering (DEF-1184)

2 Likes

You can make rocks entities - GOs with sprites of the full shape of the rock, or mini tilemaps. You can create labels for entities on a hidden layer. When the game begins you loop through the map tiles and create rocks from a factory based on which cells have labels on them. Then you sort z based on y position of the rocks once when they are created, and continuously for the hero and any other moving objects.

local layer_z = { -0.9, 0.0, 1.0 } -- layer 1, layer 2, layer 3 with default z values

go.property("layer",1) -- exposes this value to be able to be changed in editor, defaults to 1

function update(self, dt)
	local pos = go.get_position()
	pos.z = layer_z[self.layer]-pos.y*0.0001 -- start with layer z default, modify it based on y position
	go.set_position(pos)
end
2 Likes