I'm currently working with Phaser, making a game that's procedurally generated. I wanted to use some RPG maker art in my game (for reference, I'm using the RTP). I stumbled across this article, which breaks down how auto tiles work. I also stumbled across this answer which links to another article that explains auto tiling.

Here's the thing, I have no idea how I would implement something like this. I'm sure I would have to keep track of which tile sets can connect to which other tilesets (ie, some tiles have grass on the outside, and sand on the inside, so in this example I'd have to note that "grass" tiles were the outer tiles).

I've made a map generator, and I wanted to make seamless connections between my tile areas. For example, the brown areas would be "dense" areas (forests, caves, etc). The purple areas would be stone floors, and the green area is the grass. There is a tileset that works very well for things like this:

enter image description here

So I would like to use the top left grass, and the third tile set, stone, which connects to the grass.

What sorts of things would I have to consider when implementing auto tiling using these sorts of tilesets, and is there an algorithm I can look at to implement?

  • 1
    \$\begingroup\$ There's also angryfishstudios.com/2011/04/adventures-in-bitmasking \$\endgroup\$
    – jzx
    Apr 13, 2015 at 1:18
  • \$\begingroup\$ Tiled is an open source map editor which has an auto-tile implementation. You could try to find the implementation in the source-code. \$\endgroup\$
    – Philipp
    Apr 13, 2015 at 14:15
  • \$\begingroup\$ @Philipp Tiled's and RPGMaker's autotiling paradigms are different though. Tiled lets you specify the four corners of a tile as a specific terrain type ("sand", "grass", "water" and so on) and picks a matching tile based on that. RPGMaker lets you specify the centres of the tile being a specific type-surrounded-by-type variant (for example "sand inside grass", "water inside grass" and so on). Layers are used to deal with this limitation in both cases. A transformation is possible, of course; here for example using REFMAP sand-inside-grass (with grass padding): i.imgur.com/Z343MVq.png \$\endgroup\$ Apr 14, 2015 at 11:42
  • 2
    \$\begingroup\$ For the record, the RTP resources are licensed only for use with their respective software and other versions of RPG Maker. It's fine as placeholder during development, but you will need to replace them with a different graphic set for distribution - for example the REFMAP set or graphics based on the Liberated Pixel Cup. \$\endgroup\$ Apr 14, 2015 at 11:49
  • \$\begingroup\$ Thanks for the heads up @MartinSojka - For better or worse, RPG maker provides the best full set of art to work with (tiles, faces, sprites, effects, etc), but I have been limiting what I use, just so I can cover my bases when it comes time to replace them. I just didn't want to spend hours looking for art when I could be programming. Thanks for the info on Liberated Pixel Cup, I'll be looking into that later on. FWIW, I don't plan on selling this game, but if I do I definitely will replace the art. \$\endgroup\$
    – Seiyria
    Apr 14, 2015 at 12:04

1 Answer 1


I have implemented this(using the RTP) in a simple(but quite tedious) way.

I took a list of all neighbors for the current cell, and with a lot of if statements I drew the tile as 4 smaller/quarter tiles.

For me this method lead to some barely visible errors, but they can be resolved by testing for some edge-cases and correcting accordingly.

If you look at the source images and the resulting image in the RPG maker, you should be able to do this(perhaps with some trial-and-error) with if statements, identifying what the current case is for the given quarter tile and drawing accordingly.

This method can be further improved and made less tedious with bitmasks(as mentioned by jzx).

Answering your comment:

By rendering only quarter tiles, the possibilities decrease dramatically.

You shouldn't have to handle tiles on tiles, as they should be on a different layers alphablended or keycolored on each other.

Also, I don't see why would you need built-in neighbors, but that could be handled separately in the neighbor calculation, perhaps using some sort of maps(list of pairs that blend).

The map is usually static, and the images are low-res, so no need to worry about performance.

  • \$\begingroup\$ I was very keen on using bitmasks, until I saw that the complexity rises with each possible neighboring tile. Looking at the RTP, I can't quite gather how many possible cases there would be, given that some tiles can be stacked on other tiles, and some tiles have built-in neighbors. \$\endgroup\$
    – Seiyria
    Apr 13, 2015 at 14:06
  • \$\begingroup\$ @Seirya Edited answer. \$\endgroup\$
    – akaltar
    Apr 13, 2015 at 14:12
  • \$\begingroup\$ thanks for updating. One thing, though - If you look at the tileset above, you can see some tiles have built-in neighbors, like the sand-on-grass or the stone-on-grass tiles. For some tiles like the water ones, which can be placed on anything, this is not really an issue. \$\endgroup\$
    – Seiyria
    Apr 13, 2015 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .