I added auto tiling to Paper2D’s tile-map painting workflow so the surrounding tiles could determine which edges and corners to assemble. Paper2D already provided tile-map painting; my extension automated the choice of tile variants.
Build tiles from four pieces
A tile set supplies the artwork; a tile map arranges tiles on a grid. I chose an RPG Maker-style pattern that assembles each tile from four smaller pieces, or subtiles, to form the needed edges and corners.
The design uses a ruleset to generate tile-group and tile IDs, avoiding manual ID entry for each piece. Patterns remain configurable per tile set, including support for different tile types.
Choose the pattern from neighbours
I used eight-direction adjacency: the four sides and four diagonals around a tile. Bitmasking packs the yes/no results of those neighbour checks into one number. That number selects an assembly rule; it does not imply a unique sprite for every possible value.
The default rules choose which four subtiles make up each case. A data table, a table of named records, can override those choices for a tile set.
The reference combines variants 0–15 on the left with a separate example on the right: north, west, east and south have weights 1, 2, 4 and 8, with a centre terrain-type bit worth 16. The displayed binary 10011 equals 19. The project’s eight-neighbour mask has a different layout and no centre bit.
How the eight-neighbour mask is packed
The original expression assumes every directional flag is 0 or 1. It stores the result in a uint8, an unsigned eight-bit integer:
uint8 index =
(NorthWest) |
(North << 1) |
(NorthEast << 2) |
(West << 3) |
(East << 4) |
(SouthWest << 5) |
(South << 6) |
(SouthEast << 7);
The << operator moves each flag into its bit position; | combines them. From bit 0 to bit 7, the order is northwest, north, northeast, west, east, southwest, south and southeast.
This expression only packs the flags. The checks that produce them and the rules that select subtiles are separate parts of the system.
Fitting it into the editor
Bitmasking was new to me, but research and practice made the basic operation manageable. The harder part was integrating configurable patterns with Paper2D’s runtime and editor modules.
The painting fragment branches between the custom auto-tiling operation and ordinary tile placement. It includes hooks for recording edits for undo, but does not demonstrate complete undo/redo, saving, collision rebuilding or every neighbour-refresh case. Its neighbour check also leaves the intended tile-group comparison unclear.
This is a historical editor demonstration. The original post records no engine version, full source release or performance benchmark. Runtime terrain editing and compatibility with later engines are not established.
Custom painting operations and transaction hooks
The editor excerpt checks AutoTileEnabled and calls AutoTileInkedTile when enabled. These names, along with the AutoTileGroupID field used in neighbour checks, are project-specific additions to Paper2D.
Before changing the layer, the fragment calls SetFlags with RF_Transactional, then UObject::Modify(). The flag marks the object as transactional; Modify() records its state when an undo transaction is active. The excerpt does not show the complete transaction surrounding the paint operation.


