TilemapAsset

EntityAssetceramic.TilemapAsset (Class)

Asset type for loading tilemap data from various formats (TMX, LDtk). Handles loading of tilemap files, external tilesets, and associated textures.

Supported formats:

  • TMX (Tiled Map Editor): XML-based format with optional external TSX tilesets
  • LDtk (Level Designer Toolkit): JSON-based format with modern features

The asset automatically:

  • Parses tilemap data into a unified TilemapData structure
  • Loads required tileset textures
  • Handles external tileset references
  • Supports hot-reloading when files change
  • Manages texture density changes for different screen resolutions

Usage Example:

// Load a TMX tilemap
assets.add(Tilemaps.LEVEL1);
assets.load();

// Access the tilemap data
var tilemapData = assets.tilemap(Tilemaps.LEVEL1).tilemapData;

// Create a visual from the data
var tilemap = new Tilemap();
tilemap.tilemapData = tilemapData;
See: TilemapData The unified tilemap data structure, Tilemap The visual component for rendering tilemaps, TilemapParser For parsing tilemap formats

Instance Members

ldtk
ldtkData: LdtkData

If the tilemap originates from an LDtk file, this contains the complete LDtk data structure. Provides access to:

  • All levels in the project
  • Entity instances
  • Custom fields
  • Generated tilemaps

This is null for non-LDtk tilemaps.


tilemap
tmxMap: format.tmx.TmxMap

If the tilemap originates from a Tiled/TMX file, this contains the raw TMX data structure. Useful for accessing custom properties, object layers, or other TMX-specific features not converted to TilemapData.

This is null for non-TMX tilemaps.


tilemap
tilemapData: TilemapData

The unified tilemap data that can be used with Ceramic's Tilemap visual. This is the primary output of the asset, containing layers, tilesets, and tile placement data in a format-agnostic structure.

For TMX files, this contains the first/main tilemap. For LDtk files, access individual level tilemaps through ldtkData.


tilemap
invalidateTmxMap(): Void

tilemap
invalidateLdtkData(): Void

tilemap
invalidateTilemapData(): Void

tilemap
load(): Void

tilemap
destroy(): Void

Cleans up the tilemap asset and all associated data. Destroys:

  • The TilemapData instance
  • The LDtk data (if applicable)
  • References to TMX data
  • All loaded textures and sub-assets

tilemap
new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void
Name Type Default
name String
variant String (optional)
options Null<AssetOptions> (optional)

Private Members

tilemap
unobservedTmxMap: format.tmx.TmxMap

tilemap
unobservedLdtkData: LdtkData

tilemap
unobservedTilemapData: TilemapData

tilemap
tsxRawData: Map

Cache for external TSX tileset data loaded from separate files. Maps from tileset source path to raw XML content.


tilemap
ldtkExternalSources: Array<String>

List of external LDtk level file paths for hot-reload monitoring.


tilemap
emitTmxMapChange(current: format.tmx.TmxMap, previous: format.tmx.TmxMap): Void

Event when tmxMap field changes.

Name Type
current format.tmx.TmxMap
previous format.tmx.TmxMap

tilemap
emitLdtkDataChange(current: LdtkData, previous: LdtkData): Void

Event when ldtkData field changes.

Name Type
current LdtkData
previous LdtkData

tilemap
emitTilemapDataChange(current: TilemapData, previous: TilemapData): Void

Event when tilemapData field changes.

Name Type
current TilemapData
previous TilemapData

tilemap
loadTmxTiledMap(): Void

Loads a TMX (Tiled Map Editor) format tilemap. Handles:

  1. Loading the main TMX file
  2. Loading external TSX tilesets if referenced
  3. Parsing the XML data into TmxMap structure
  4. Converting to unified TilemapData
  5. Loading all required textures

tilemap
loadExternalTsxTilesetData(rawTmxData: String, done: Function): Void

Loads external TSX tileset files referenced by the TMX map. TSX files allow sharing tilesets between multiple maps.

This method:

  • Parses the TMX to find external tileset references
  • Checks the cache for already-loaded TSX data
  • Loads any missing TSX files
  • Caches the results for future use
Name Type Description
rawTmxData String The raw TMX XML content
done Function Callback with success status

tilemap
addTilesetTextAsset(textAssets: Assets, source: String): Void

Adds a text asset for loading an external TSX tileset file.

Name Type Description
textAssets Assets The Assets instance to add the asset to
source String The relative path to the TSX file from the TMX location

tilemap
resolveTsxRawData(name: String, cwd: String): String

Resolves raw TSX data from the cache by filename. Called by the parser when it encounters an external tileset reference.

Name Type Description
name String The TSX filename to resolve
cwd String The current working directory (unused but part of parser interface)
Returns Description
String The raw TSX XML content, or null if not loaded

tilemap
loadTextureFromSource(source: String, configureAsset: Function, done: Function): Void

Loads a texture from a source path, used by tileset loading.

This method:

  • Checks if the texture is already loaded
  • Creates an ImageAsset if needed
  • Configures the asset (e.g., for filtering)
  • Shares loaded textures with the owner Assets instance
  • Sets NEAREST filter by default (pixel-perfect for tilemaps)
Name Type Description
source String The relative path to the image file
configureAsset Function Optional callback to configure the ImageAsset
done Function Callback that receives the loaded texture (or null on failure)

tilemap
loadLdtk(): Void

Loads an LDtk (Level Designer Toolkit) format tilemap project.

Handles:

  1. Loading the main .ldtk JSON file
  2. Loading external level files if the project uses them
  3. Parsing the LDtk data structure
  4. Loading tileset textures for all levels
  5. Generating TilemapData for each level

The skip option in AssetOptions can exclude specific levels from loading.


tilemap
loadExternalLdtkLevelData(source: String, callback: Function): Void

Loads an external LDtk level file (.ldtkl). Used when LDtk projects are configured to save levels in separate files.

Name Type Description
source String The path to the external level file
callback Function Receives the raw level JSON data, or null on failure

tilemap
texturesDensityDidChange(newDensity: Float, prevDensity: Float): Void

Handles texture density changes for responsive asset loading. Called when the screen density changes (e.g., moving between displays).

Name Type Description
newDensity Float The new texture density multiplier
prevDensity Float The previous texture density multiplier

tilemap
checkTexturesDensity(): Void

Checks and updates textures for the current screen density. Currently a no-op as tileset textures handle density changes themselves, but kept for potential future use.


tilemap
assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): Void

Handles file change notifications for hot-reloading. Automatically reloads the tilemap when:

  • The main tilemap file changes
  • Any external level files change (LDtk)
  • Any referenced tileset files change
Name Type Description
newFiles ReadOnlyMap<String, Float> Map of current file paths to modification times
previousFiles ReadOnlyMap<String, Float> Map of previous file paths to modification times

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