Skip to content

Kiln API / kiln / AnimationController

Class: AnimationController ​

One entity's playback of a graph. Systems use it through SpriteAnimator / Animator rows (with Mut(...) to write): set(param, value), trigger(name), play(state), and read state, time, normalizedTime, finished, is(state), get(param).

Extended by ​

Constructors ​

Constructor ​

ts
new AnimationController(graph, play?): AnimationController;

Parameters ​

ParameterType
graphAnimationGraph | null
play?string

Returns ​

AnimationController

Properties ​

graph ​

ts
graph: AnimationGraph | null;

state ​

ts
state: string = '';

The current state's name ('' until the clips are known).


time ​

ts
time: number = 0;

Seconds of clip time since the state was entered (keeps growing across loops).


speed ​

ts
speed: number = 1;

Playback rate for the whole animator, multiplied with each state's speed.


paused ​

ts
paused: boolean = false;

Holds the playhead (events and transitions wait too).


params ​

ts
readonly params: Record<string, number | boolean> = {};

Parameter values; write them with set().


triggers ​

ts
readonly triggers: Set<string>;

Triggers set since the last animation step.


fade ​

ts
fade: Fade | null = null;

The crossfade in progress, or null.


request ​

ts
protected request: 
  | {
  state: string;
  fade: number | undefined;
  restart: boolean;
}
  | null = null;

play() requests, applied at the start of the next animation step.


startState ​

ts
protected startState: string | null;

The state to enter first, overriding the graph's initial state.

Accessors ​

stateSpec ​

Get Signature ​

ts
get stateSpec(): AnimationStateSpec | undefined;

The current state's spec.

Returns ​

AnimationStateSpec | undefined


clip ​

Get Signature ​

ts
get clip(): string;

The current state's clip name.

Returns ​

string


loop ​

Get Signature ​

ts
get loop(): LoopMode;

The current state's loop mode.

Returns ​

LoopMode


normalizedTime ​

Get Signature ​

ts
get normalizedTime(): number;

Plays of the current clip so far: 0..1 through the first, 1 at the end of a 'once' clip, 2.5 halfway through a third loop.

Returns ​

number


finished ​

Get Signature ​

ts
get finished(): boolean;

A 'once' clip has reached its end.

Returns ​

boolean


weight ​

Get Signature ​

ts
get weight(): number;

The crossfade weight of the current state: 0 just after a faded transition, 1 when settled.

Returns ​

number


bound ​

Get Signature ​

ts
get bound(): boolean;

True once the plugin has told the controller about its clips.

Returns ​

boolean

Methods ​

set() ​

ts
set(name, value): this;

Sets a parameter declared in the graph's params.

Parameters ​

ParameterType
namestring
valuenumber | boolean

Returns ​

this


get() ​

ts
get(name): number | boolean | undefined;

A parameter's value.

Parameters ​

ParameterType
namestring

Returns ​

number | boolean | undefined


trigger() ​

ts
trigger(name): this;

Sets a trigger declared in the graph's triggers. It lasts one animation step unless a transition takes it.

Parameters ​

ParameterType
namestring

Returns ​

this


play() ​

ts
play(state, options?): this;

Enters a state at the next animation step, skipping transitions. Already in it: nothing, unless restart. fade overrides the graph's crossfade seconds.

Parameters ​

ParameterType
statestring
options{ fade?: number; restart?: boolean; }
options.fade?number
options.restart?boolean

Returns ​

this


is() ​

ts
is(state): boolean;

True when the current state is state.

Parameters ​

ParameterType
statestring

Returns ​

boolean


bind() ​

ts
bind(clips, what): void;

Called by the plugin when the clips are known. Checks every state's clip exists, then enters the first state.

Parameters ​

ParameterType
clipsReadonlyMap<string, ClipInfo>
whatstring

Returns ​

void


clipInfo() ​

ts
clipInfo(name): ClipInfo | undefined;

Info for a clip by name.

Parameters ​

ParameterType
namestring

Returns ​

ClipInfo | undefined


step() ​

ts
step(dt, out): void;

One animation step of dt seconds: play() requests, then transitions, then the playhead and its events.

Parameters ​

ParameterType
dtnumber
outAnimationSink

Returns ​

void


toJSON() ​

ts
toJSON(): Record<string, unknown>;

Returns ​

Record<string, unknown>