Background
Background

Integrating an auto tiling system in to the Paper2D Plugin

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.

Editor recording of dark terrain growing around a stone structure, with rocky borders changing as cells are painted.
Original editor recording: terrain borders update as the painted area grows.

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.

Colour-coded RPG Maker autotile diagram, with source pieces on the left and assembled borders, corners and filled shapes on the right.
Assembly reference, cropped from Tommy Gun’s Autotile Guide, Cracked Rabbit Gaming (CC BY 3.0 US).

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.

Tile-set editor crop with a red outline around a grass tile group and a blue grid dividing its source pieces.
Red marks a tile group; blue divides the source pieces used by its rules.

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.

Reference composite showing tile variants numbered 0 to 15 on the left, and four directional weights plus a centre terrain bit producing binary 10011, or 19, on the right.
Reference illustration edited from Sonny Bone’s tile-bitmasking tutorial, Envato Tuts+.

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.

Move over the bright dot and follow the line. P pauses. Escape closes the game.

Sigil Trace

Move over the sigil before time runs out.

Score0000
Spells00
Best on this browser0000
I · KINDLE SPELL 01
START

Trace the Sigil with your mouse

Start at the glowing dot and follow the line. No click needed.

or press Enter
Move your mouse onto the bright dot. No click needed.