This post talks about 2d maps created in Tiled, and how we implemented walls and
Y-order. You may think about it as Z-order, but as our maps are flat, we only need to arrange things by their Y coordinate.
On thin walls in Tiled
How do I know which tile in Tiled is passable, and which is not?
Especially that we have such a luxury as thin walls.
My answer is Tiled feature – Terrains (https://doc.mapeditor.org/en/stable/manual/terrain/),
AKA Wang tiles (a good article for gamedevs: https://dev.to/joestrout/wang-2-corner-tiles-544k).
If a side of a tile has a terrain named “wall”, it’s not passable – as simple as that.
This way, our level designers don’t have to mark up the map – the walls are already in the tileset.
On Y-order
So, our objects (and object layers in Tiled) do have Y coordinate, so we know in what order
to draw them.
But what about tiles on a map?
What if our maps have multiple complex layers, maybe even a tree of layers?
What if these layers have similar objects with different Y coordinates, like multiple trees
or pillars or whatever?
Shall the level designer split each object into a separate layer and assign it a Y-order property?
This sounds like too much manual work, prone to error.
Our answer is – automatically split layers into “island” segments, and internally set
each segment’s Y-order according to the lowest tile (with the highest Y).
3 segments for 3 trees on a single layer, with a different Y-order
The next step is to only assign Y-order to segments based on the walls
assigned to tiles of that segment. The engine reasonably assumes that
a wall is on a floor level, and everything above it is fluff – tree top,
wall bottom, and so on.
Think of a door mat:
This is more precise, because sometimes our wall tiles have tiles
both above and below them.