TilemapAsset
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;
Instance Members
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.
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.
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.
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
Name | Type | Default |
---|---|---|
name |
String | |
variant |
String | (optional) |
options |
Null<AssetOptions> | (optional) |
Private Members
Cache for external TSX tileset data loaded from separate files. Maps from tileset source path to raw XML content.
List of external LDtk level file paths for hot-reload monitoring.
Event when tmxMap field changes.
Name | Type |
---|---|
current |
format.tmx.TmxMap |
previous |
format.tmx.TmxMap |
Event when ldtkData field changes.
Name | Type |
---|---|
current |
LdtkData |
previous |
LdtkData |
Event when tilemapData field changes.
Name | Type |
---|---|
current |
TilemapData |
previous |
TilemapData |
Loads a TMX (Tiled Map Editor) format tilemap. Handles:
- Loading the main TMX file
- Loading external TSX tilesets if referenced
- Parsing the XML data into TmxMap structure
- Converting to unified TilemapData
- Loading all required textures
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 |
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 |
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 |
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) |
Loads an LDtk (Level Designer Toolkit) format tilemap project.
Handles:
- Loading the main .ldtk JSON file
- Loading external level files if the project uses them
- Parsing the LDtk data structure
- Loading tileset textures for all levels
- Generating TilemapData for each level
The skip
option in AssetOptions can exclude specific levels from loading.
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 |
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 |
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.
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() |