TilemapLdtkParser
ceramic.TilemapLdtkParser (Class)
Parser that converts LDtk level data into Ceramic tilemap data structures.
This class handles:
- Parsing raw LDtk JSON data
- Converting LDtk tilesets to Ceramic tilesets with proper GID mapping
- Converting LDtk layers (Tiles, IntGrid, AutoLayer, Entities) to tilemap layers
- Loading external level data for multi-file projects
- Optimizing tile stacking for rendering performance
The parser maintains compatibility between LDtk's tile ID system and Ceramic's global tile ID (GID) system.
Instance Members
Parses raw LDtk JSON data into an LdtkData structure.
Name | Type | Description |
---|---|---|
rawLdtkData |
String | The raw JSON string from an LDtk project file |
loadExternalLdtkLevelData |
Function | Callback to load external level files (for multi-file projects) |
Returns | Description |
---|---|
LdtkData | The parsed LdtkData object, or null if parsing fails |
Loads and converts all tilesets and tilemaps from LDtk data.
This method:
- Converts LDtk tilesets to Ceramic tilesets with proper GID assignment
- Loads tileset textures through the provided callback
- Creates tilemap data for all levels (if not using external levels)
Name | Type | Default | Description |
---|---|---|---|
ldtkData |
LdtkData | The parsed LDtk data | |
loadTexture |
Function | (optional) | Optional callback to load tileset textures |
skip |
Array<String> | Array of texture paths to skip loading |
Converts an LDtk level into Ceramic tilemap data.
This method:
- Creates TilemapData with level properties
- Converts each layer instance to TilemapLayerData
- Handles different layer types (Tiles, IntGrid, AutoLayer, Entities)
- Optimizes tile stacking and alpha blending
The resulting tilemap data is stored in level.ceramicTilemap.
Name | Type | Description |
---|---|---|
level |
LdtkLevel | The LDtk level to convert |
Private Members
ldtk
convertLdtkTiles(ldtkTiles: Array<Int>, tileset: LdtkTilesetDefinition, cols: Int, rows: Int, gridSize: Int, tilesAlpha: Array<Float>, tilesOffsetX: Array<Int>, tilesOffsetY: Array<Int>): Array<TilemapTile>
Converts LDtk tile data to Ceramic tilemap tiles.
LDtk stores tiles as flat arrays with [tileId, flipBits, x, y, srcX, srcY, alpha] for each tile. This method converts that to Ceramic's TilemapTile format.
Special handling:
- Stacks multiple tiles at the same position
- Optimizes opaque tiles by removing hidden tiles beneath
- Preserves tile offsets and alpha values
Name | Type | Description |
---|---|---|
ldtkTiles |
Array<Int> | Raw tile data from LDtk (7 integers per tile) |
tileset |
LdtkTilesetDefinition | The tileset definition for GID mapping |
cols |
Int | Number of columns in the layer |
rows |
Int | Number of rows in the layer |
gridSize |
Int | The grid cell size in pixels |
tilesAlpha |
Array<Float> | Output array for tile alpha values |
tilesOffsetX |
Array<Int> | Output array for tile X offsets |
tilesOffsetY |
Array<Int> | Output array for tile Y offsets |
Returns | Description |
---|---|
Array<TilemapTile> | Array of TilemapTile objects, or null if no tiles |