Tilemap z-order

Hey everyone!
I need some help with tilemaps. I’m trying to create depth (sort of top down view) in my game but I don’t really know how to get the z-ordering to work inside the tilemap.

I noticed that there was a fix recently for this (Defold 1.2.161 has been released), but I just don’t understand how it works or what I should be doing. Worth noting is that I’m creating the map in tiled and exporting it to .tilemap

Here’s what my structure looks like right now:

Any help is appreciated! :slight_smile:

The fix in 1.2.161 was that tilemaps with multiple layers now can have sprites mixed in between layers. In older versions of Defold all layers of a tilemap were rendered together.

The tilemap component itself has one z-value and individual layers can be offset from the component z-value. The layers get sorted and rendered just like any other visual component and can end up in front of or behind other components based on the aggregated final z-value (taking into account hierarchies of game objects).

Aha! I see! Thank you for the very speedy reply :slight_smile:

Another question, is there any way of setting the z value of a tile layer from code, alternative move tiles to different layers from code? Otherwise, what would be the best approach if I want to be able to move in front or behind tiles in the game?

Actually, I think I can fix it by just use game objects and a factory instead :slight_smile:

1 Like

You can do it using tilemap.get_tile() and set_tile()

1 Like