Skip nav

Connected tiles graphics

As you know I’m a dev not an illustrator and it’s hard for me to draw images for my game. I love doing it and I choose a simple style for this reason but when I can, I try to reduce the work load using code. This is an example of exactly that.

As you must know if you’re reading this when you do a 2D game using a tilemap you need to handle connected tiles. If you have no idea how connected tiles works in 2D games I suggest you go read : Adventures in Bitmasking.

In my top down game it’s usefull for walls, mountains and rivers for example.
It’s simple, for each connected tile, we check the North, South, East ,West neighbour and add a value if the connection exist. This give us an int between 0 and 15 we just need to show the correct image for this tile. 

So we need 16 image for a Wall, but it’s a pain to draw 16 images for each connected item.
If we look at the final image we can see that we can use the corners of 4 of the images to generate 12 of them:

Here are the images we will use:

  • 0 connections (0)
  • 2 connections (E/W - 6)
  • 2 connections (N/S - 9)
  • 4 connections (N/S/E/W - 15)

After that we just need to copy each corner at the correct position, you can find a simplified version of my code below (I use a custom library for drawing and reading images, but you can use PIL in python or do this directly in Unity if you want to)

Tile connections:

Image generator:

Connected Tiles, Tile Graphics, Tilemap

One of my favourite quotes

Never be cruel. Never be cowardly. Remember, hate is always foolish and love is always wise. Always try to be nice, but never fail to be kind. (Doctor Who/12th)

© 2010-2023 All Rights Reserved.
Website   (build: 2023-01-23T02:18:39.148Z)