Log In  

Cart #autotiledemo-2 | 2019-12-23 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA


  • Left Click: Draw Tiles
  • Right Click: Erase Tiles
  • Z/X: Switch Tileset Theme


Lately I've been playing around with procedurally generated platformer levels and as part of that I started exploring an autotiling function. The goal was to be able to generate a level layout using one algorithm, then apply autotiling to theme the level.

How It Works

The autotile function has a signature similar to map. It accepts six arguments, an x and y coordinate of the map, the width and height in map tiles to apply the autotiling to, the sprite to use as a rule tile for tiling, and a table containing bitmask data for each rule.

The bitmask rules look like this, {0b00000000, 2}, where the first value is the mask and the second value is the sprite id to replace the rule tile with. The second argument can also be a table of tiles to randomly choose from if you want to have a variety of tiles for a give position.


Each bit of the bitmask corresponds to a possible surrounding tile starting from the top left, down to the bottom right. Here's an example of how a bitmask translates to the relative tiles:

-- Given A Bitmask

-- Where X is the tile being evaluated

-- The current tile has tiles above, below, and on either side.

Project Status

I'm not sure yet what else I want to do with this but I figured I'd post it and see if anyone had any questions or ideas. The entire cartridge is more verbose than it needs to be to help with understanding, but I'd be happy to hear how you all would change it.

Thanks for taking a look!

P#71349 2019-12-23 18:40

holy smokes. i think i am reading this correctly and that is awesome.

P#71482 2019-12-29 00:26

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-09-18 17:47 | 0.016s | 2097k | Q:28