AutoTiler
Component that automatically processes tilemap tiles to apply auto-tiling rules. Auto-tiling analyzes neighboring tiles and replaces them with appropriate variants to create seamless connections and transitions.
The AutoTiler supports multiple auto-tiling algorithms (EDGE_16, EDGE_CORNER_32, EXPANDED_47, etc.) and can handle complex tile arrangements including:
- Edge connections (straight borders)
- Corner pieces (diagonal connections)
- Overlapping tiles for detailed transitions
- Custom tile mappings for different tileset standards
Usage Example:
// Define auto-tiles for grass terrain
var grassAutoTile = {
kind: EXPANDED_47,
gid: 10, // Base grass tile GID
bounds: true // Connect with map edges
};
// Create auto-tiler
var autoTiler = new AutoTiler([grassAutoTile]);
// Add to tilemap layer
tilemapLayer.component(autoTiler);
The component automatically updates when the layer's tiles change, recomputing auto-tiling for affected areas.
Static Members
Static lookup table mapping 8-bit masks to tile indices for EDGE_CORNER_32 auto-tiling. The mask encodes which edges and corners connect to matching tiles. Built lazily on first access.
Static lookup table for EXPANDED_BOTTOM_CORNER_26 auto-tiling. Maps 47-tile indices to their 26-tile equivalents, removing top corners. Built lazily on first access.
Static lookup table for TILESETTER_BLOB_47 tile positions. Maps tile indices to X,Y offsets in the Tilesetter blob layout. Built lazily on first access.
Inverted lookup table for EDGE_CORNER_32 mapping. Maps tile indices back to their 8-bit mask values. Built lazily on first access.
Validates whether a given edge/corner combination is valid for EDGE_CORNER_32 tiling.
Rules enforced:
- If all corners are present, all edges must also be present
- A corner can only exist if both adjacent edges are present (e.g., top-left corner requires both left and top edges)
This validation ensures visually correct tile connections without impossible configurations like floating corners.
Name | Type | Description |
---|---|---|
value |
Int | 8-bit value encoding edges (bits 0-3) and corners (bits 4-7) |
Returns | Description |
---|---|
Bool | true if the combination is valid, false otherwise |
Instance Members
The tilemap layer data this auto-tiler processes. Automatically bound when added as a component to a TilemapLayerData entity.
Read-only array of auto-tile configurations. Each auto-tile defines a GID and algorithm for processing tiles.
new(autoTiles: Array<AutoTile>, ?handleComputeTile: Function, ?handleComputeTiles: Function): Void
Creates a new AutoTiler with the specified auto-tile configurations.
Name | Type | Default | Description |
---|---|---|---|
autoTiles |
Array<AutoTile> | Array of auto-tile rules to apply | |
handleComputeTile |
Function | (optional) | Optional callback for each computed tile |
handleComputeTiles |
Function | (optional) | Optional callback after all tiles are computed |
Private Members
Internal map for fast lookup of auto-tiles by their GID. Built during construction from the autoTiles array.
emitComputeTile(autoTiler: AutoTiler, autoTile: AutoTile, computedTiles: Array<TilemapTile>, index: Int): Void
Event fired when a single tile is computed during auto-tiling. Useful for custom post-processing or debugging tile placement.
Name | Type | Description |
---|---|---|
autoTiler |
AutoTiler | This AutoTiler instance |
autoTile |
AutoTile | The auto-tile rule that was applied |
computedTiles |
Array<TilemapTile> | The array of computed tiles being built |
index |
Int | The index of the tile that was just computed |
Event fired after all tiles have been computed but before they are applied to the layer. Allows for final adjustments to the tile array.
Name | Type | Description |
---|---|---|
autoTiler |
AutoTiler | This AutoTiler instance |
computedTiles |
Array<TilemapTile> | The complete array of computed tiles |
Called when this auto-tiler is bound as a component to a TilemapLayerData. Sets up event listeners and performs initial auto-tiling computation.
handleTilesChange(tiles: ReadOnlyArray<TilemapTile>, prevTiles: ReadOnlyArray<TilemapTile>): Void
Handles changes to the layer's tile data. Automatically recomputes auto-tiling when tiles are modified.
Name | Type | Description |
---|---|---|
tiles |
ReadOnlyArray<TilemapTile> | The new tile array |
prevTiles |
ReadOnlyArray<TilemapTile> | The previous tile array (before the change) |
Core auto-tiling computation method. Analyzes each tile in the layer and applies appropriate auto-tiling transformations based on neighboring tiles.
The algorithm:
- Iterates through each tile position
- Checks if the tile matches any auto-tile rule
- Examines neighboring tiles (4 cardinal + 4 diagonal)
- Computes edge and corner masks based on matches
- Selects appropriate tile variant from the tileset
- Handles overlapping tiles for detailed transitions
Name | Type | Description |
---|---|---|
tiles |
ReadOnlyArray<TilemapTile> | The source tile array to process |
Name | Type |
---|---|
entity |
Entity |
Returns |
---|
Entity |
Metadata
Name | Parameters |
---|---|
:build |
ceramic.macros.ComponentMacro.build() |
:autoBuild |
ceramic.macros.ComponentMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |