Skip to content

Documentation / scene / AnimationController

Class: AnimationController

Defined in: libs/scene/src/animation/animationcontroller.ts:101

Event-driven animation state controller.

Each state owns one serializable timeline. External gameplay events are dispatched to the current timeline first, then to the current state's response table, so different states can respond to the same event differently.

Extends

Constructors

Constructor

new AnimationController(animationSet): AnimationController

Defined in: libs/scene/src/animation/animationcontroller.ts:117

Create a controller for an animation set.

Parameters

animationSet

AnimationSet

Animation set that owns the clips and active playbacks.

Returns

AnimationController

Overrides

Observable<AnimationControllerEventMap>.constructor

Properties

animationSet

readonly animationSet: AnimationSet

Defined in: libs/scene/src/animation/animationcontroller.ts:105

Animation set used to create playbacks for all state timelines.

Accessors

currentState

Get Signature

get currentState(): string

Defined in: libs/scene/src/animation/animationcontroller.ts:132

Current state name.

Returns

string

The active state name, or null when the controller is stopped or has not entered a state.


runner

Get Signature

get runner(): AnimationTimelineRunner

Defined in: libs/scene/src/animation/animationcontroller.ts:141

Current timeline runner.

Returns

AnimationTimelineRunner

The active timeline runner, or null when no state is running.

Methods

on()

on<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:594

IEventTarget.on

Type Parameters

K

K extends keyof AnimationControllerEventMap

Parameters

type

K

listener

EventListener<AnimationControllerEventMap, K>

context?

unknown

Returns

void

Inherited from

Observable.on


once()

once<K>(type, listener, context?): void

Defined in: libs/base/dist/index.d.ts:598

IEventTarget.once

Type Parameters

K

K extends keyof AnimationControllerEventMap

Parameters

type

K

listener

EventListener<AnimationControllerEventMap, K>

context?

unknown

Returns

void

Inherited from

Observable.once


off()

off<K>(type, listener?, context?): void

Defined in: libs/base/dist/index.d.ts:602

IEventTarget.off

Type Parameters

K

K extends keyof AnimationControllerEventMap

Parameters

type

K

listener?

EventListener<AnimationControllerEventMap>

context?

unknown

Returns

void

Inherited from

Observable.off


dispatchEvent()

dispatchEvent<K>(type, ...args): void

Defined in: libs/base/dist/index.d.ts:606

IEventTarget.dispatchEvent

Type Parameters

K

K extends keyof AnimationControllerEventMap

Parameters

type

K

args

...AnimationControllerEventMap[K]

Returns

void

Inherited from

Observable.dispatchEvent


addState()

addState(name, definition): AnimationController

Defined in: libs/scene/src/animation/animationcontroller.ts:152

Register or replace a named state definition.

Parameters

name

string

Unique state name.

definition

AnimationControllerStateDefinition

Timeline and event response configuration for the state.

Returns

AnimationController

This controller for chaining.


hasState()

hasState(name): boolean

Defined in: libs/scene/src/animation/animationcontroller.ts:166

Test whether a state has been registered.

Parameters

name

string

State name to look up.

Returns

boolean

True if the controller contains a state with the given name; otherwise false.


setState()

setState(name, options?): AnimationTimelineRunner

Defined in: libs/scene/src/animation/animationcontroller.ts:181

Enter a registered state.

If the requested state is already current and options.force is not set, this returns the existing runner without restarting the timeline. When a transition duration is provided, the previous runner fades out while the entry plays of the new state fade in.

Parameters

name

string

State name to enter.

options?

AnimationControllerSetStateOptions

Optional transition, re-entry, and stop behavior.

Returns

AnimationTimelineRunner

The active runner for the entered state, or null if the state does not exist.


dispatch()

dispatch(event, payload?): AnimationTimelineEventResult

Defined in: libs/scene/src/animation/animationcontroller.ts:234

Dispatch a gameplay event to the active state.

The active timeline receives the event first. If it does not handle the event, the current state's response table may consume it, enqueue or run steps, or transition to another state.

Parameters

event

string

Event name to dispatch.

payload?

unknown

Optional event payload passed through result notifications.

Returns

AnimationTimelineEventResult

The resolved handling result for the event.


stop()

stop(options?): void

Defined in: libs/scene/src/animation/animationcontroller.ts:292

Stop the active state and clear the current state.

Parameters

options?

StopAnimationOptions

Optional stop behavior applied to playbacks owned by the active runner.

Returns

void

void


dispose()

dispose(): void

Defined in: libs/scene/src/animation/animationcontroller.ts:308

Stop playback and remove all registered states.

Returns

void

void

Released under the MIT License.