TilemapEditor
Interactive tilemap editor component that enables in-game tile painting and erasing.
This component can be attached to a Tilemap entity to enable runtime editing functionality, allowing users to paint tiles with left-click and erase them with right-click. It supports continuous painting while dragging and interpolates between positions for smooth lines.
Usage Example
// Create a tilemap and enable editing
var tilemap = new Tilemap();
tilemap.tilemapData = myTilemapData;
// Attach editor to allow painting on the 'main' layer
var editor = new TilemapEditor('main', grassTile, emptyTile);
tilemap.component(editor);
// Listen for edit events
editor.onFill(this, index -> {
trace('Filled tile at index: $index');
});
Instance Members
The tilemap entity this editor is attached to. Set automatically when used as a component.
The name of the tilemap layer to edit. Must match an existing layer in the tilemap data.
The tile value to apply when filling (left-click). This can be a tile ID from a tileset or a special value.
The tile value to apply when erasing (right-click). Typically 0 to represent an empty tile.
Whether editing is currently enabled. Set to false to temporarily disable user interaction.
Called when this editor is attached to a tilemap as a component. Sets up the necessary event listeners for pointer interaction.
new(?layerName: String = "main", ?fillValue: TilemapTile = 1, ?eraseValue: TilemapTile = 0): Void
Creates a new tilemap editor.
Name | Type | Default | Description |
---|---|---|---|
layerName |
String | "main" |
The name of the layer to edit (default: 'main') |
fillValue |
TilemapTile | 1 |
The tile value for filling (default: 1) |
eraseValue |
TilemapTile | 0 |
The tile value for erasing (default: 0) |
Private Members
ID of the button currently being held down (-1 if none). 0 = left button, 2 = right button.
The tile value being painted with the current button. Cached to ensure consistency during drag operations.
Map tracking which tiles have been painted during the current drag. Prevents painting the same tile multiple times in one stroke.
Last painted X position in visual coordinates. Used for interpolating smooth lines when dragging.
Last painted Y position in visual coordinates. Used for interpolating smooth lines when dragging.
tileIndexAtPosition(tilemapData: TilemapData, layerData: TilemapLayerData, x: Float, y: Float): Int
Calculates the tile index at a given position in visual coordinates. Takes into account layer offsets and tile dimensions.
Name | Type | Description |
---|---|---|
tilemapData |
TilemapData | The tilemap data containing layer information |
layerData |
TilemapLayerData | The specific layer data to check against |
x |
Float | The X position in visual coordinates |
y |
Float | The Y position in visual coordinates |
Returns | Description |
---|---|
Int | The tile index at the position, or -1 if outside bounds |
Event emitted when a tile is filled with the fill value.
Name | Type | Description |
---|---|---|
index |
Int | The tile index that was filled |
Event emitted when a tile is erased with the erase value.
Name | Type | Description |
---|---|---|
index |
Int | The tile index that was erased |
Handles pointer down events to start tile painting or erasing. Left-click starts filling tiles, right-click starts erasing.
Name | Type | Description |
---|---|---|
info |
TouchInfo | Touch/mouse event information |
Handles pointer up events to stop tile painting or erasing. Cleans up the drag state when the mouse button is released.
Name | Type | Description |
---|---|---|
info |
TouchInfo | Touch/mouse event information |
Handles pointer move events during tile painting or erasing. Interpolates between the last and current positions to paint smooth lines, ensuring no tiles are missed when moving the pointer quickly.
Name | Type | Description |
---|---|---|
info |
TouchInfo | Touch/mouse event information |
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() |