SpineMontage

Entityceramic.SpineMontage (Class)
Implements: Component

A powerful utility for managing and orchestrating Spine animations as a cohesive montage.

SpineMontage provides a high-level interface for configuring, sequencing, and controlling Spine animations with predefined settings. It allows you to group related animations together and define transitions, callbacks, and default behaviors for each animation state.

The class supports both enum-based and string-based animation keys through its generic type parameter T, making it type-safe when used with enums while still flexible for dynamic animation names.

Key features:

  • Type-safe animation management with enum support
  • Animation chaining and sequencing with automatic transitions
  • Per-animation configuration (speed, loop, track, skin)
  • Begin/complete callbacks for animation lifecycle events
  • Default settings that apply to all animations
  • Automatic Spine instance lifecycle management

Using with an enum

enum HeroAnimation {
    IDLE;
    WALK;
    RUN;
    JUMP;
    ATTACK;
}

var montage = new SpineMontage<HeroAnimation>({
    spine: {
        data: heroSpineData,
        scale: 0.5
    },
    defaults: {
        track: 0,
        speed: 1.0
    },
    animations: {
        IDLE: { anim: "idle", loop: true },
        WALK: { anim: "walk", loop: true, speed: 1.2 },
        RUN: { anim: "run", loop: true, speed: 1.5 },
        JUMP: { anim: "jump", next: IDLE },
        ATTACK: {
            anim: "attack",
            next: IDLE,
            complete: () -> trace("Attack finished!")
        }
    },
    start: Idle
});

// Later in code
montage.play(Walk);
montage.play(Attack); // Will auto-transition to Idle when complete

Using with strings

var montage = new SpineMontage<String>();
montage.createSpine(spineData);
montage.set("intro", { anim: "intro_animation", next: "loop" });
montage.set("loop", { anim: "loop_animation", loop: true });
montage.play("intro");

Instance Members

spine
spine: Spine

The Spine instance this montage controls.

When setting a new Spine instance:

  • Previous instance event listeners are cleaned up
  • If the previous instance was bound, it gets destroyed
  • Current animation (if any) is reapplied to the new instance

The Spine instance can be bound to this montage's lifecycle, meaning it will be automatically destroyed when the montage is destroyed.


spine
animation: ceramic.SpineMontage.T

The currently playing animation in the montage.

Setting this property will:

  1. Stop the current animation (if any)
  2. Apply the new animation's configuration
  3. Execute any begin callback
  4. Emit the beginAnimation event
  5. Start playing the animation on the Spine instance

Set to null to stop all animations and hide the Spine instance.


spine
defaults: SpineMontageDefaults

Default animation settings that apply to all animations unless overridden.

These defaults include:

  • track: The animation track to use (default: 0)
  • speed: Time scale multiplier (default: 1.0)
  • loop: Whether animations loop by default (default: false)
  • skin: Default skin name to use (default: null)

Individual animations can override any of these defaults.


spine
initializerName: String

spine
destroy(): Void

spine
setAnimations(animations: Dynamic): Void

Sets multiple animation configurations at once using a dynamic object.

Each field in the animations object should have a name matching the animation key (as a string) and a value of type SpineMontageAnimation containing the configuration for that animation.

Name Type Description
animations Dynamic Object with animation configurations keyed by name

spine
setDefaults(defaults: SpineMontageDefaults): Void

Sets the default animation parameters that apply to all animations.

These defaults are used as fallback values when an animation doesn't specify its own value for a particular setting.

Name Type Description
defaults SpineMontageDefaults The default configuration to use

spine
useSpine(spine: Spine, ?bound: Bool = true): Void

Associates an existing Spine instance with this montage.

This method allows you to provide a pre-configured Spine instance rather than creating a new one. Any previously associated Spine instance will be properly cleaned up based on its binding status.

Name Type Default Description
spine Spine The Spine instance to use
bound Bool true Whether to bind the Spine instance lifecycle to this montage. When true, destroying either object will destroy the other.

spine
createSpine(spineData: SpineData, ?bound: Bool = true): Void

Creates a new Spine instance using the provided SpineData.

This is a convenience method that creates and configures a new Spine instance with the given data. The created instance is automatically set as inactive until an animation is played.

Name Type Default Description
spineData SpineData The SpineData containing skeleton and atlas information
bound Bool true Whether to bind the created Spine instance lifecycle to this montage. When true, destroying either object will destroy the other.

spine
stop(): Void

Stops the current animation and hides the Spine instance.

This is equivalent to setting animation = null and will:

  • Stop any playing animation
  • Hide the Spine instance (set active to false)
  • Clear the current animation state

spine
play(animation: ceramic.SpineMontage.T, ?reset: Bool = false): Void

Plays the specified animation.

This is the primary method for starting animations in the montage. By default, if the same animation is already playing, it continues without interruption. Use the reset parameter to force a restart.

Name Type Default Description
animation ceramic.SpineMontage.T The animation key to play
reset Bool false If true, forces the animation to restart from the beginning, even if it's already the current animation * haxe montage.play(HeroAnimation.Walk); montage.play(HeroAnimation.Jump, true); // Force restart

spine
set(key: ceramic.SpineMontage.T, animationInstance: SpineMontageAnimation<ceramic.SpineMontage.T>): Void

Configures a single animation in the montage.

Use this method to add or update the configuration for a specific animation key. The configuration includes the actual Spine animation name, playback settings, callbacks, and transition information.

Name Type Description
key ceramic.SpineMontage.T The animation key to configure
animationInstance SpineMontageAnimation<ceramic.SpineMontage.T> The configuration for this animation * haxe montage.set(HeroAnimation.Victory, { anim: "victory_dance", speed: 0.8, complete: () -> trace("Victory!"), next: HeroAnimation.Idle });

spine
get(key: ceramic.SpineMontage.T): SpineMontageAnimation<ceramic.SpineMontage.T>

Retrieves the configuration for a specific animation key.

Name Type Description
key ceramic.SpineMontage.T The animation key to look up
Returns Description
SpineMontageAnimation<ceramic.SpineMontage.T> The animation configuration if found, null otherwise

spine
new(?settings: SpineMontageSettings<ceramic.SpineMontage.T>): Void

Creates a new SpineMontage instance with optional initial configuration.

The settings parameter allows you to configure all aspects of the montage at creation time, including:

  • Creating or using an existing Spine instance
  • Setting default animation parameters
  • Defining all animation configurations
  • Specifying an initial animation to play
Name Type Default Description
settings SpineMontageSettings<ceramic.SpineMontage.T> (optional) Optional configuration object containing spine setup, animation definitions, and default values. See SpineMontageSettings for detailed options.

Private Members

spine
animationInstances: Map

Internal storage for animation configurations mapped by their string representation. For enum-based montages, enum values are converted to strings for storage. This allows the same storage mechanism to work for both enum and string keys.


spine
currentAnimationInstance: SpineMontageAnimation<ceramic.SpineMontage.T>

The animation configuration currently being used to display an animation. This holds the complete configuration including animation name, speed, loop settings, etc. Will be null when no animation is playing.


spine
boundToSpineInstance: Bool

Indicates whether the Spine instance lifecycle is bound to this montage. When true:

  • Destroying the montage will also destroy the Spine instance
  • Destroying the Spine instance will also destroy the montage This creates a strong ownership relationship between the two objects.

spine
numSetAnimation: Int

Internal counter tracking animation changes. Used to detect when animations are changed externally during callbacks, preventing the montage from overriding explicit animation changes.


spine
enumType: Enum<ceramic.SpineMontage.T>

Stores the enum type when T is an enum. Currently unused but reserved for potential future enum-specific features.


spine
emitBeginAnimation(animation: ceramic.SpineMontage.T): Void

Fired when starting an animation. This event is emitted after the animation has been applied to the Spine instance and after any begin callback has been executed.

Name Type Description
animation ceramic.SpineMontage.T The animation key that just started

spine
emitCompleteAnimation(animation: ceramic.SpineMontage.T): Void

Fired when completing an animation. This event is emitted when a non-looping animation finishes playing, after any complete callback has been executed but before transitioning to the next animation (if configured).

Name Type Description
animation ceramic.SpineMontage.T The animation key that just completed

spine
bindAsComponent(): Void

spine
handleSpineDestroy(_: Entity): Void
Name Type
_ Entity

spine
handleSpineComplete(): Void

spine
applyCurrentAnimation(): Void

spine
keyToString(key: ceramic.SpineMontage.T): String
Name Type
key ceramic.SpineMontage.T
Returns
String

spine
setByName(name: String, animationInstance: SpineMontageAnimation<ceramic.SpineMontage.T>): Void

Configure an animation for key matching name name.

Name Type
name String
animationInstance SpineMontageAnimation<ceramic.SpineMontage.T>

spine
getByName(name: String): SpineMontageAnimation<ceramic.SpineMontage.T>

Get configured animation for key matching name name

Name Type
name String
Returns
SpineMontageAnimation<ceramic.SpineMontage.T>

spine
setEntity(entity: Entity): Void
Name Type
entity Entity

spine
getEntity(): Entity
Returns
Entity

Metadata

Name Parameters
:build ceramic.macros.ComponentMacro.build()
:autoBuild ceramic.macros.ComponentMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()