Day 105 — Handling Layers in Tilemap

Hey and welcome.

Much like ogres, Tilemaps have layers and if you can use them right they can really work in your favour and streamline 2D level design for you.

The layer system for Tilemaps works very similar to the layers we worked with in the 2D Space Shooter in which certain layers can be given priority over others so that you can have foreground and background elements.

Currently we only have one layer that’s holding our ground, if you try painting some cavern tiles in you can end up overwriting the ground tiles in there. Let’s go ahead and fix that, in your hierarchy you should have a Grid object that contains the Tilemap object you created earlier. Go ahead and right click the Grid object and choose 2D Object > Tilemap > Rectangular and call this Midground_Tilemap.

In the inspector for both of these objects you’ll spot the Sorting Layer and Order In Layer properties under additional settings.

We don’t need to worry about the Sorting Layer currently but go ahead and set the order for your midground to 0 and then set your ground Tilemap order to 1. Now in your Tile Palette you should see your Midground_Tilemap in the drop down list, go ahead and select that and get painting and you should be getting something like this as you do now:

Pretty cool right? Already it starts to bring more life to the game, make sure to add in a couple of open holes as we’re going to be putting something in those. You’ll also notice in the gif here that you can click on the dropdown in the bottom right in order to focus on the current Tilemap layer that you’re working on. This means that even if you’re painting behind something you’ll be able to see which tiles you’re filling in!

Once you’re happy with how your midground layer is looking go ahead and create a Farground_Tilemap object now. With this one you can set the order to -1 which will put it behind your Midground layer. It would be better to have your layers ordered as 0, 1 and 2 but I’ve done it here to show that you can set this as a negative number if you wanted.

With that done though you can switch to your Farground_Tilemap in the Tile Palette same as before and you can start adding in your pieces in the empty gaps you’ve left.

When you’re happy with everything you should have a spooky looking scene similar to below but definitely have a play about with it if you have a better vision in mind, the only really important part that’s need is that gap in the ground that the player can fall down:

Use this as a chance to add in some vegetation and spikes at the bottom of the pit too!

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.