TilemapEditor

Entityceramic.TilemapEditor (Class)
Implements: Component

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

tilemap
tilemap: Tilemap

The tilemap entity this editor is attached to. Set automatically when used as a component.


tilemap
layerName: String

The name of the tilemap layer to edit. Must match an existing layer in the tilemap data.


tilemap
fillValue: TilemapTile

The tile value to apply when filling (left-click). This can be a tile ID from a tileset or a special value.


tilemap
eraseValue: TilemapTile

The tile value to apply when erasing (right-click). Typically 0 to represent an empty tile.


tilemap
enabled: Bool

Whether editing is currently enabled. Set to false to temporarily disable user interaction.


tilemap
initializerName: String

tilemap
bindAsComponent(): Void

Called when this editor is attached to a tilemap as a component. Sets up the necessary event listeners for pointer interaction.


tilemap
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

tilemap
buttonDownId: Int

ID of the button currently being held down (-1 if none). 0 = left button, 2 = right button.


tilemap
buttonDownValue: Int

The tile value being painted with the current button. Cached to ensure consistency during drag operations.


tilemap
hoveredTileIndexes: IntBoolMap

Map tracking which tiles have been painted during the current drag. Prevents painting the same tile multiple times in one stroke.


tilemap
lastPaintedX: Float

Last painted X position in visual coordinates. Used for interpolating smooth lines when dragging.


tilemap
lastPaintedY: Float

Last painted Y position in visual coordinates. Used for interpolating smooth lines when dragging.


tilemap
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

tilemap
emitFill(index: Int): Void

Event emitted when a tile is filled with the fill value.

Name Type Description
index Int The tile index that was filled

tilemap
emitErase(index: Int): Void

Event emitted when a tile is erased with the erase value.

Name Type Description
index Int The tile index that was erased

tilemap
handlePointerDown(info: TouchInfo): Void

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

tilemap
handlePointerUp(info: TouchInfo): Void

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

tilemap
handlePointerMove(info: TouchInfo): Void

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

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