[SOLVED] Tilemap with 3 layers and z index not working as expected

Hi all!

I just edited the default “Platform Game” template. I created a tilemap with 3 layers:

  • background (Z index set to 0.0)
  • midground (Z index set to 0.1)
  • foreground (Z index set to 0.2)

everything works fine in the Defold editor:

  • the fence is in the background
  • the grass and the terrain are in the midground
  • the “red dots” are in the foreground

everything is also fine the game.collection preview:

The issue is when I run the game; z-index is in the reverse order:

  • background (the fence) is rendered on top (and the grass that are in the midground are moving behind)
  • foreground (the red dots) are not displayed (since they are rendered behind the midground)

If I change the Z-index in the editor as following (switching background and foreground z-index):

  • background (Z index set to 0.2)
  • midground (Z index set to 0.1)
  • foreground (Z index set to 0.0)

the game runs correctly (but the editor do not show them correctly and it is challenging to create maps in this way.

What I’m missing?

Are you using a camera component which is looking at your game from the other direction?

thank you!

Simple as that: I just changed the Near Z and Far Z properties of the camera component.

1 Like