AtlasAsset

EntityAssetceramic.AtlasAsset (Class)

Asset for loading texture atlases (sprite sheets with metadata).

AtlasAsset handles loading of texture atlas files which contain multiple packed textures/sprites along with their position metadata. It supports both Spine/LibGDX atlas format (.atlas) and XML atlas formats.

Features:

  • Automatic texture loading for all atlas pages
  • Hot-reload support for atlas files
  • Density-aware loading (e.g., @2x variants)
  • Automatic visual updates when atlas is reloaded
  • Custom atlas parser support

The loaded atlas can be used with Quad visuals to display specific regions:

// Load an atlas
var atlasAsset = new AtlasAsset('myAtlas');
atlasAsset.path = 'atlases/sprites.atlas';
atlasAsset.onComplete(this, success -> {
    if (success) {
        // Get a specific region from the atlas
        var region = atlasAsset.atlas.region('player_idle');

        // Use it with a Quad
        var quad = new Quad();
        quad.tile = region;

        // Use it with a Sprite
        // (requires sprite plugin) Sprite has better atlas region support than Quad:
        // region offsets are properly handled, allowing trimmed/packed sprites
        // to display correctly with their original bounds and pivot points.
        var sprite = new Sprite();
        sprite.region = region;
    }
});
assets.addAsset(atlasAsset);
assets.load();

Instance Members

The loaded texture atlas containing all regions and pages. Will be null until the asset is successfully loaded.


text: String

The raw text content of the atlas file. Can be used to inspect the atlas metadata.


invalidateAtlas(): Void

invalidateText(): Void

load(): Void

Loads the atlas asset.

This method:

  1. Loads the atlas metadata file
  2. Parses the atlas format (auto-detects XML or text format)
  3. Loads all texture pages referenced in the atlas
  4. Updates existing visuals if this is a reload

The loading process is asynchronous and will emit a complete event when finished (either success or failure).


destroy(): Void

Destroys the atlas asset and its loaded atlas. This will also destroy all texture pages associated with the atlas.


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

Private Members

unobservedAtlas: TextureAtlas

unobservedText: String

emitReplaceAtlas(newAtlas: TextureAtlas, prevAtlas: TextureAtlas): Void

Emitted when the atlas is replaced (typically during hot-reload).

Name Type Description
newAtlas TextureAtlas The newly loaded atlas
prevAtlas TextureAtlas The previous atlas that was replaced

emitAtlasChange(current: TextureAtlas, previous: TextureAtlas): Void

Event when atlas field changes.

Name Type
current TextureAtlas
previous TextureAtlas

emitTextChange(current: String, previous: String): Void

Event when text field changes.

Name Type
current String
previous String

parseAtlas(text: String): TextureAtlas

A custom atlas parsing method. Will be used over the default parsing if not null. This allows you to provide your own atlas format parser. The parser should take the raw atlas text and return a TextureAtlas instance.

Name Type
text String
Returns
TextureAtlas

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

Called when the global texture density changes. Triggers a reload if a different density variant exists.

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

checkTexturesDensity(): Void

Checks if the atlas needs to be reloaded due to texture density change. If a different density variant exists (e.g., @2x version), it will reload the atlas.


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

Called when asset files change on disk (hot-reload support). Automatically reloads the atlas if its file has been modified.

Name Type Description
newFiles ReadOnlyMap<String, Float> Map of current files and their modification times
previousFiles ReadOnlyMap<String, Float> Map of previous files and their 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()