Change the z order of specific tiles in a Tiled map

Hey guys! Like many of you, I’m using Tiled to create my maps, and I have a problem I can’t seem to overcome on my own when implementing them in GDevelop:

Top-down maps usually boil down to 3 layers: Under the player, on par with the player, and above the player.

For the first option, you just need to make sure the player’s z value is above the tilemap’s.
For the second option, you can use the collision mask and set up a “move player away” event so the player won’t be able to pass the tiles in question.

For the third option, however, I am unsure about the best way to achieve that. I was thinking of changing the z order of a specified class through collision masks, but from what I can see GDevelop only supports changing the z order of the whole tilemap, not singular tiles.

The workaround I’m using right now is to export only the “below the player” tiles as a tilemap, and then the “above the player” tiles as a png (and naturally give it a higher z value than the player in GDevelop). This does work mostly, but:

  1. I am concerned about performance when loading an extra image every time I load a tilemap.
  2. There seems to be a small bug with my approach, as sometimes the png gets offset by one pixel while moving, which leads to unpleasant looking lines:

For the above reasons, my current solution is suboptimal, which is why I’d like to know how you handle these situations. Is there maybe a function I’m overlooking? Please let me know!

Thanks in advance :slight_smile:

You can actually do this directly with 1 tilemap file (but multiple tilemap objects)
Add the tiles that should be above as a different layer in your tilemap.
Then add the tilemap as 2 different objects, but select the tile layers on both of them. (This is the “layer index” field, also ensure “display mode” is set to “index”)
Then place the “higher” tilemap on the scene as a higher z order.

1 Like

Thank you for the fast answer! It’s awesome to hear that this can be set up easily. The only problem is that there doesn’t seem to be any documentation on how Tiled indexes work, so I am a bit unsure of what number to put in there.

I assume it would be the number next to “ID” in Tiled, but this only works for the number 1, which shows my floor layer. When I choose any other number as the index in GDevelop, it doesn’t show anything; I tried both individual layer IDs and group IDs. Am I missing something here or is my Tiled map bugged?

The Tile Index is based off the tile layers you built out in Tiled. The lowest layer starts at 0, and goes up for each layer above it in the Layers list in Tiled.

It appears index display is broken in 5.0.140, but here’s how it should work, based off 5.0.138. I’ll open up an issue report on the github about this.

For example, in the Not-A-Vania example from the main example list, this is how the layers are set up in tiled:
image

If I add it to the scene with display mode all, here’s what a section looks like:

If I add it to the scene with display mode index, and the index of 0, here’s what it looks like:

If I use an index of 2, here’s what it looks like:

Edit: I’ve created an issue on Github for the index mode not working, Tilemap Index Mode Broken since 5.0.139 · Issue #4247 · 4ian/GDevelop · GitHub

Thanks again for the explanation and the creation of the Github issue! Looking forward to the solution :smiley:

The devs worked quick on this one. A change has already been applied, and will be available in the next release. I’ve tested and confirmed that the dev build does in fact resolve the index issue (along with some other Tilemap rendering issues from other threads).

Amazing! I appreciate the fast help by both you and the developers.

By the way, may I suggest adding the info about indexes and how to use them in the documentation here: Tilemap object [GDevelop wiki]

I am sure I am not the only one who didn’t know about this feature before :smiley: