TilemapParser

ceramic.TilemapParser (Class)

Universal tilemap parser supporting multiple tilemap formats.

TilemapParser provides a unified interface for parsing different tilemap file formats and converting them to Ceramic's TilemapData structure. Currently supports TMX (Tiled Map Editor) format, with optional LDtk support when the ldtk plugin is enabled.

Features

  • TMX Support: Full parsing of Tiled Map Editor (.tmx) files
  • TSX Support: External tileset (.tsx) file loading
  • LDtk Support: Level Designer Toolkit parsing (requires ldtk plugin)
  • Tileset Caching: Automatically caches parsed tilesets for performance
  • Texture Loading: Supports custom texture loading callbacks

Usage Example

var parser = new TilemapParser();

// Parse TMX file
var tmxMap = parser.parseTmx(tmxContent);

// Convert to TilemapData with texture loading
var tilemapData = parser.tmxMapToTilemapData(tmxMap,
    (source, configureAsset, done) -> {
        // Load texture from source path
        var texture = assets.texture(source);
        done(texture);
    }
);

// Apply to tilemap
var tilemap = new Tilemap();
tilemap.tilemapData = tilemapData;

Instance Members

ldtk
parseLdtk(rawLdtkData: String, loadExternalLdtkLevelData: Function): LdtkData

Parse LDtk file

Name Type Description
rawLdtkData String Raw LDtk data as string
loadExternalLdtkLevelData Function
Returns Description
LdtkData The LDtk parsed data

ldtk
loadLdtkTilemaps(ldtkData: LdtkData, ?loadTexture: Function, skip: Array<String>): Void
Name Type Default
ldtkData LdtkData
loadTexture Function (optional)
skip Array<String>

tilemap
clearCache(): Void

Clear cached data (if any). Only tileset data is cached because it can be shared between maps. Normally not needed to clear manually unless working with a lot of different tilesets.


tilemap
parseTmx(rawTmxData: String, ?cwd: String, ?resolveTsxRawData: Function): format.tmx.TmxMap

Parse TMX Tilemap (Tiled Map Editor format)

Name Type Default Description
rawTmxData String Raw TMX data as string
cwd String (optional) Current working directory. Needed to identify cached tileset relative to their tilemap
resolveTsxRawData Function (optional) A method to resolve TSX Tileset data that are not embedded in TMX data (optional)
Returns Description
format.tmx.TmxMap The TMX map data

tilemap
parseExternalTilesetNames(rawTmxData: String): Array<String>

Extracts the names of all external tileset files referenced in a TMX file. This is useful for pre-loading TSX files before parsing the main TMX.

Name Type Description
rawTmxData String The raw TMX XML data as a string
Returns Description
Array<String> Array of external tileset filenames (relative paths as specified in TMX)

tilemap
tmxMapToTilemapData(tmxMap: format.tmx.TmxMap, ?loadTexture: Function): TilemapData

Converts a parsed TMX map to Ceramic's TilemapData format. This method handles the conversion of all map properties, tilesets, and layers.

Name Type Default Description
tmxMap format.tmx.TmxMap The parsed TMX map data
loadTexture Function (optional) Optional callback for loading tileset textures. If provided, will be called for each tileset image with (source, configureAsset, done) parameters
Returns Description
TilemapData A new TilemapData instance ready to be used with a Tilemap visual

tilemap
new(): Void

Creates a new tilemap parser instance.

Private Members

tilemap
tmxParser: TilemapTmxParser

Internal TMX parser instance, created lazily when needed.


tilemap
ldtkParser: TilemapLdtkParser

Internal LDtk parser instance, created lazily when needed.