How to make an autotile tileset
- Draw a 5-tile template in your pixel editor. Use one row of five square tiles with an even size such as 16, 24 or 32 px. The tiles must be in this order: isolated, vertical, horizontal, inner corners, fill.
- Drop the template above. You can also click Load a sample template to see the format, or download the sample and draw over it.
- Check the random preview map. Every edge and corner should join cleanly. If something looks off, fix that quarter of the matching template tile.
- Export the tileset PNG and the bitmask JSON, or both as a ZIP.
Using the tileset in code
// tileset.json from this tool
const BITS = { N: 1, NE: 2, E: 4, SE: 8, S: 16, SW: 32, W: 64, NW: 128 };
function tileFor(map, x, y) {
const same = (dx, dy) => map[y + dy]?.[x + dx] === map[y][x];
let m = 0;
if (same(0, -1)) m |= BITS.N; if (same(1, -1)) m |= BITS.NE;
if (same(1, 0)) m |= BITS.E; if (same(1, 1)) m |= BITS.SE;
if (same(0, 1)) m |= BITS.S; if (same(-1, 1)) m |= BITS.SW;
if (same(-1, 0)) m |= BITS.W; if (same(-1, -1)) m |= BITS.NW;
return tileset.lookup[m]; // index into the tileset PNG
}
The tile at index i is at column i % columns and row floor(i / columns) in the PNG. The JSON also lists each tile's pixel position.
Engine notes
- Godot 4: import the PNG as a TileSet atlas. Then either assign terrain peering bits by hand, or skip Godot's terrain system and place tiles from code with the lookup table above.
- Unity: create a Rule Tile (2D Tilemap Extras) and assign the generated tiles. The JSON's mask values tell you which neighbors each tile expects.
- Phaser / custom engines: the lookup array is all you need. Compute the mask for each cell and draw the matching frame.
Why only 5 tiles?
Each tile corner only depends on three neighbors: the two sides next to it and the diagonal between them. That gives just five possible corner shapes. If you draw each shape once, in all four corners of a template tile, the generator can assemble every one of the 47 combinations.
This is the same quarter-tile method classic RPG engines used for their autotiles.