TilemapLayerData
Data model representing a single layer within a tilemap.
TilemapLayerData holds all the information needed to render and interact with a tilemap layer, including tile indices, dimensions, positioning, and visual properties. This is a reactive Model that notifies observers when properties change, allowing TilemapLayer visuals to update automatically.
Features
- Tile Storage: Holds tile indices referencing tilesets via global IDs (GIDs)
- Auto-tiling Support: Can store both original and computed tiles after auto-tiling
- Per-tile Properties: Supports per-tile alpha and offset values
- Layer Properties: Position, size, visibility, opacity, and blending modes
- Reactive Updates: Extends Model for automatic change notifications
Usage Example
// Create a new layer data
var layer = new TilemapLayerData();
layer.name = 'collision';
layer.grid(20, 15); // 20x15 tiles
layer.tileSize(32, 32); // 32x32 pixel tiles
// Set tiles (array of TilemapTile values)
var tiles = [];
for (i in 0...300) {
tiles.push(i == 150 ? 1 : 0); // Single tile in center
}
layer.tiles = tiles;
// Configure visual properties
layer.opacity = 0.8;
layer.color = Color.RED;
Instance Members
Reference to the source LDtk layer instance when this layer was imported from LDtk. Provides access to additional LDtk-specific data and properties.
The name of the layer
The x position of the layer in tiles
The y position of the layer in tiles
The width of the layer in tiles
The height of the layer in tiles
The opacity of the layer
Whether this layer is visible or not
X offset for this layer in points.
Y offset for this layer in points.
Explicit depth, or null of that should be computed by Tilemap
instead
Tile default blending
Tile default (tint) color
Extra tile default blending
Extra tile default alpha
Tiles
Per-tile alpha, or null if there is no custom alpha per tile
Per-tile x offset in pixels, or null if there is no offset
Per-tile y offset in pixels, or null if there is no offset
Computed tiles, after applying auto-tiling (if any).
Will be null
if no auto-tiling is used.
Per-computed tile alpha, or null if there is no custom alpha per computed tile
Per-computed tile x offset in pixels, or null if there is no offset per computed tile
Per-computed tile y offset in pixels, or null if there is no offset per computed tile
Is true
if this layer has tiles. Some layers don't have tile and
don't need to be rendered with tilemap layer quads, but are still
available as containers to add custom objects (like LDtk entities).
Is true
(default) if this layer should have its tiles rendered (if any).
The width of a tile in this layer
The height of a tile in this layer
A shorthand to set columns
and rows
Name | Type | Description |
---|---|---|
columns |
Int | * |
rows |
Int |
A shorthand to set x
and y
Name | Type |
---|---|
x |
Int |
y |
Int |
A shorthand to set offsetX
and offsetY
Name | Type |
---|---|
offsetX |
Int |
offsetY |
Int |
A shorthand to set tileWidth
and tileHeight
Name | Type | Description |
---|---|---|
tileWidth |
Int | * |
tileHeight |
Int |
Converts column and row coordinates to a tile index.
Name | Type | Description |
---|---|---|
column |
Int | The column position (0-based) |
row |
Int | The row position (0-based) |
Returns | Description |
---|---|
Int | The tile index in the flat tiles array |
Retrieves the tile at the specified column and row position from the tiles array.
Name | Type | Description |
---|---|---|
column |
Int | The column position (0-based) |
row |
Int | The row position (0-based) |
Returns | Description |
---|---|
TilemapTile | The TilemapTile at the position |
Retrieves the computed tile at the specified column and row position. Used when auto-tiling has been applied to get the final tile value.
Name | Type | Description |
---|---|---|
column |
Int | The column position (0-based) |
row |
Int | The row position (0-based) |
Returns | Description |
---|---|
TilemapTile | The computed TilemapTile at the position |
Gets the column position from a tile index.
Name | Type | Description |
---|---|---|
index |
Int | The tile index in the flat array |
Returns | Description |
---|---|
Int | The column position (0-based) |
Gets the row position from a tile index.
Name | Type | Description |
---|---|---|
index |
Int | The tile index in the flat array |
Returns | Description |
---|---|
Int | The row position (0-based) |
Private Members
Event when ldtkLayer field changes.
Name | Type |
---|---|
current |
LdtkLayerInstance |
previous |
LdtkLayerInstance |
Event when name field changes.
Name | Type |
---|---|
current |
String |
previous |
String |
Event when x field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when y field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when columns field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when rows field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when opacity field changes.
Name | Type |
---|---|
current |
Float |
previous |
Float |
Event when visible field changes.
Name | Type |
---|---|
current |
Bool |
previous |
Bool |
Event when offsetX field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when offsetY field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when explicitDepth field changes.
Name | Type |
---|---|
current |
Null<Float> |
previous |
Null<Float> |
Event when blending field changes.
Name | Type |
---|---|
current |
Blending |
previous |
Blending |
Event when color field changes.
Name | Type |
---|---|
current |
Color |
previous |
Color |
Event when extraBlending field changes.
Name | Type |
---|---|
current |
Blending |
previous |
Blending |
Event when extraOpacity field changes.
Name | Type |
---|---|
current |
Float |
previous |
Float |
emitTilesChange(current: ReadOnlyArray<TilemapTile>, previous: ReadOnlyArray<TilemapTile>): Void
Event when tiles field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<TilemapTile> |
previous |
ReadOnlyArray<TilemapTile> |
Event when tilesAlpha field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Float> |
previous |
ReadOnlyArray<Float> |
Event when tilesOffsetX field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Int> |
previous |
ReadOnlyArray<Int> |
Event when tilesOffsetY field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Int> |
previous |
ReadOnlyArray<Int> |
emitComputedTilesChange(current: ReadOnlyArray<TilemapTile>, previous: ReadOnlyArray<TilemapTile>): Void
Event when computedTiles field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<TilemapTile> |
previous |
ReadOnlyArray<TilemapTile> |
emitComputedTilesAlphaChange(current: ReadOnlyArray<Float>, previous: ReadOnlyArray<Float>): Void
Event when computedTilesAlpha field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Float> |
previous |
ReadOnlyArray<Float> |
emitComputedTilesOffsetXChange(current: ReadOnlyArray<Int>, previous: ReadOnlyArray<Int>): Void
Event when computedTilesOffsetX field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Int> |
previous |
ReadOnlyArray<Int> |
emitComputedTilesOffsetYChange(current: ReadOnlyArray<Int>, previous: ReadOnlyArray<Int>): Void
Event when computedTilesOffsetY field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<Int> |
previous |
ReadOnlyArray<Int> |
Event when hasTiles field changes.
Name | Type |
---|---|
current |
Bool |
previous |
Bool |
Event when shouldRenderTiles field changes.
Name | Type |
---|---|
current |
Bool |
previous |
Bool |
Event when tileWidth field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when tileHeight field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |
:build |
tracker.macros.SerializableMacro.build() |
:autoBuild |
tracker.macros.SerializableMacro.build() |