SpineAsset
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 dataskeleton.atlas
- Texture atlas definitionskeleton.png
- One or more texture pages
Usage Example
var spineAsset = assets.spine('hero');
var spine = new Spine();
spine.spineData = spineAsset.spineData;
Instance Members
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.
The fully loaded Spine data ready for use in animations. Contains skeleton structure, animations, and texture references.
Scale factor applied to the skeleton data. Use this to adjust the size of Spine animations at load time. Default is 1.0.
Map of atlas pages to their corresponding image assets. Used internally to manage texture loading and lifecycle.
Loads the Spine asset files.
This method:
- Discovers JSON and atlas files in the asset folder
- Loads the JSON skeleton data
- Loads the atlas file and its texture pages
- Creates the SpineData instance
- Handles hot-reload if files were previously loaded
Cleans up the asset and releases all resources. Destroys the SpineData and all associated textures.
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
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 |
Event when spineData field changes.
Name | Type |
---|---|
current |
SpineData |
previous |
SpineData |
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 |
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 |
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 |
Checks if texture density change requires reloading the asset. This happens when different density atlases are available.
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() |