I don't know if it's important to how your game works to actually make the tile have depth information or just APPEAR to have depth. If appearing to have depth is ok, then here's the way I addressed this in my tile engine:
Each map has a two-dimensional array of MapCell
objects. A MapCell
can be thought of as a "tile slot" in that it represents an area on the map where a tile would be drawn.
Now, each MapCell
has two (it could be more, but I only use two) MapCellLayer
objects. The first MapCellLayer
object is always defined, but the second one is optional (i.e. often == null
).
A MapCellLayer
can have up to five Tile
objects. Tile
objects represent the actual tiles being drawn to the screen and hold a reference to the tile index from the tilesheet. The reason there are five Tile
objects is because of how they're drawn and used. They're set up like this:
- Ground - This is the base tile, it's drawn on the screen first and appears below all other tiles in the
MapCell
and the players.
- Mask 1 - This tile is drawn second (if it exists) and provides a way to add tiles with alpha transparency over top of the ground tile. It's drawn below the player.
- Mask 2 - This is exactly the same as the Mask 1 tile except it's drawn after to allow for even more control of the map by overlaying more tiles.
- Fringe 1 - This tile is drawn after Mask 2 and is effectively the same as Mask 1 with the only exception being that it is drawn OVER the player. Players get drawn between Mask 2 and Fringe 1.
- Fringe 2 - You may have guessed it already, but this is the same as Fringe 1, but drawn over it.
My draw call works like this:
Loop through all the MapCells within the camera's view.
Loop through all MapCellLayers for the current MapCell
If the layer exists
Draw the Ground tile if it exists
Draw the Mask 1 tile if it exists
Draw the Mask 2 tile if it exists
Draw the Player on the tile if any
Draw the Fringe 1 tile if it exists
Draw the Fringe 2 tile if it exists
End if layer exists
End MapCellLayer loop
End MapCell loop
A few notes:
- If you you build your maps with this system, you can create some advanced looking terrain features with the right tileset. See my example pictures below.
- The point of the MapCellLayer is so that I can have areas where two players occupy the same cell but one is above another one such as on bridges or inside houses (i.e. first and second floor, although inside houses I only draw the MapCellLayer that the player is on).
- I don't actually draw the players in the tile loop, I just wanted to make it simple. I actually make use of
SpriteSortMode.FrontToBack
so that each layer has it's own values and gets drawn in the correct order. The player/npc loop is then done separately. I recommend this method especially if your players/npcs are larger than a single tile.
Here's some example pictures from one of the maps in my game. I've taken screenshots working up from drawing only Ground tiles to all tiles up to Fringe 2. The player is stationary.
Ground

+ Mask 1 (Note the use of transparency on the bushes and tree roots.)

+ Mask 2 (Note the ladder being drawn over the rock wall from Mask 1.)

+ Fringe 1 (Note that the player is being drawn behind the tree.)

+ Fringe 2 (Note how the branches of the pink tree on the right now overlap the ones from the tree on the left.)

I hope this helps you. Let me know if you have any questions.