SpineAsset

EntityAssetceramic.SpineAsset (Class)

Asset loader for Spine 2D skeletal animation data.

This asset handles loading Spine JSON files along with their associated texture atlases and images. It automatically manages:

  • JSON skeleton data parsing
  • Atlas file loading with texture page management
  • Hot-reloading when source files change
  • Texture density switching for different screen resolutions
  • Spine data lifecycle and memory management

File Structure

A typical Spine asset folder contains:

  • skeleton.json - The skeleton and animation data
  • skeleton.atlas - Texture atlas definition
  • skeleton.png - One or more texture pages

Usage Example

var spineAsset = assets.spine('hero');
var spine = new Spine();
spine.spineData = spineAsset.spineData;

Instance Members

spine
json: String

The raw JSON string containing the skeleton data. Available after the asset is loaded.


The parsed texture atlas containing all texture regions. Maps skeleton attachments to texture coordinates.


spine
spineData: SpineData

The fully loaded Spine data ready for use in animations. Contains skeleton structure, animations, and texture references.


spine
scale: Float

Scale factor applied to the skeleton data. Use this to adjust the size of Spine animations at load time. Default is 1.0.


spine
pages: Map

Map of atlas pages to their corresponding image assets. Used internally to manage texture loading and lifecycle.


spine
invalidateSpineData(): Void

spine
load(): Void

Loads the Spine asset files.

This method:

  1. Discovers JSON and atlas files in the asset folder
  2. Loads the JSON skeleton data
  3. Loads the atlas file and its texture pages
  4. Creates the SpineData instance
  5. Handles hot-reload if files were previously loaded

spine
destroy(): Void

Cleans up the asset and releases all resources. Destroys the SpineData and all associated textures.


spine
new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void

Creates a new Spine asset.

Name Type Default Description
name String The asset name (typically the folder name containing Spine files)
variant String (optional) Optional variant for different asset versions
options Null<AssetOptions> (optional) Asset loading options, including scale factor

Private Members

spine
unobservedSpineData: SpineData

spine
atlasAsset: TextAsset

spine
emitReplaceSpineData(newSpineData: SpineData, prevSpineData: SpineData): Void

Emitted when the spine data is replaced during hot-reload. This allows Spine instances to update their data automatically.

Name Type Description
newSpineData SpineData The newly loaded spine data
prevSpineData SpineData The previous spine data being replaced

spine
emitSpineDataChange(current: SpineData, previous: SpineData): Void

Event when spineData field changes.

Name Type
current SpineData
previous SpineData

spine
loadPage(page: spine.support.graphics.AtlasPage, path: String, ?basePath: String): Void

Loads a texture page for the atlas.

Called by the SpineTextureLoader when the atlas references a texture. Creates an ImageAsset for each texture page and tracks it.

Name Type Default Description
page spine.support.graphics.AtlasPage The atlas page to load
path String The texture file path
basePath String (optional) Optional base directory path

spine
unloadPage(page: spine.support.graphics.AtlasPage): Void

Unloads a texture page from memory.

Removes the page from tracking and destroys its image asset.

Name Type Description
page spine.support.graphics.AtlasPage The atlas page to unload

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

Called when the texture density changes (e.g., switching to @2x textures). Triggers a reload if the atlas path changes due to density.

Name Type
newDensity Float
prevDensity Float

spine
checkTexturesDensity(): Void

Checks if texture density change requires reloading the asset. This happens when different density atlases are available.


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

Handles hot-reload when asset files change on disk. Automatically reloads the Spine data when source files are modified.

Name Type
newFiles ReadOnlyMap<String, Float>
previousFiles ReadOnlyMap<String, Float>

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