AutoTiler

Entityceramic.AutoTiler (Class)
Implements: Component

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.

See: AutoTile For auto-tile configuration, AutoTileKind For supported algorithms, TilemapLayerData For the tilemap data structure

Static Members

tilemap
edgeCorner32Map: ReadOnlyArray<Int>

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.


tilemap
expandedBottomCorner26Map: ReadOnlyArray<Int>

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.


tilemap
tilesetterBlob47Map: ReadOnlyArray<Int>

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.


tilemap
edgeCorner32InvertedMap: ReadOnlyArray<Int>

Inverted lookup table for EDGE_CORNER_32 mapping. Maps tile indices back to their 8-bit mask values. Built lazily on first access.


tilemap
isValidEdgeCorner32Combination(value: Int): Bool

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

tilemap
layerData: TilemapLayerData

The tilemap layer data this auto-tiler processes. Automatically bound when added as a component to a TilemapLayerData entity.


tilemap
autoTiles: ReadOnlyArray<AutoTile>

Read-only array of auto-tile configurations. Each auto-tile defines a GID and algorithm for processing tiles.


tilemap
initializerName: String

tilemap
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

tilemap
gidMap: IntMap<AutoTile>

Internal map for fast lookup of auto-tiles by their GID. Built during construction from the autoTiles array.


tilemap
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

tilemap
emitComputeTiles(autoTiler: AutoTiler, computedTiles: Array<TilemapTile>): Void

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

tilemap
bindAsComponent(): Void

Called when this auto-tiler is bound as a component to a TilemapLayerData. Sets up event listeners and performs initial auto-tiling computation.


tilemap
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)

tilemap
computeAutoTiles(tiles: ReadOnlyArray<TilemapTile>): Void

Core auto-tiling computation method. Analyzes each tile in the layer and applies appropriate auto-tiling transformations based on neighboring tiles.

The algorithm:

  1. Iterates through each tile position
  2. Checks if the tile matches any auto-tile rule
  3. Examines neighboring tiles (4 cardinal + 4 diagonal)
  4. Computes edge and corner masks based on matches
  5. Selects appropriate tile variant from the tileset
  6. Handles overlapping tiles for detailed transitions
Name Type Description
tiles ReadOnlyArray<TilemapTile> The source tile array to process

tilemap
setEntity(entity: Entity): Void
Name Type
entity Entity

tilemap
getEntity(): 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()