Skip to content

AnimationPlayer ​

Frame-by-frame sprite animation.

ts
import { AnimationSequence, AnimationPlayer } from "willow";

AnimationSequence ​

ts
class AnimationSequence

Defines a named sequence of texture frames for sprite animation. Plays through frames at fps frames per second, optionally looping.

AnimationSequence: constructors ​

ts
new AnimationSequence(config?: any)
new AnimationSequence(name: string, frames: Array<TextureRegion>, fps?: float, loop?: boolean)

AnimationSequence: properties ​

MemberDescription
name: stringName of this animation sequence (e.g. "idle", "walk", "jump").
frames: Array<TextureRegion>Array of texture regions representing each frame in order.
fps: floatPlayback speed in frames per second (default 10.0).
loop: booleanWhen true, wraps back to frame 0 after the last frame; otherwise stops at the final frame.

AnimationPlayer ​

ts
class AnimationPlayer

Manages playback of multiple named animation sequences on a node or sprite. Advances frames over time and updates the bound node's texture region accordingly.

Stepping rule: a player whose node is in the scene (added under Scene.main.root) is stepped by the scene's frame, so it needs no update(dt) call. A script that calls update(dt) itself keeps driving the player: once it has, the scene leaves that player alone and it is never advanced twice in a frame. A player whose node is not in the scene is stepped only by your own update(dt) calls.

AnimationPlayer: constructors ​

ts
new AnimationPlayer(node?: Node)

AnimationPlayer: properties ​

MemberDescription
readonly current: stringName of the currently active sequence, or empty string if none.
readonly frame: intZero-based index of the current frame within the active sequence.
readonly isPlaying: booleanTrue while an animation sequence is actively playing.

AnimationPlayer: methods ​

MemberDescription
addSequence(seq: AnimationSequence): voidRegisters a named animation sequence with this player.
play(name: string): voidStarts playing the named sequence from frame 0. No-op if already playing it.
playFrom(name: string, frame: int): voidStarts playing the named sequence from a specific frame index.
stop(): voidPauses or stops playback at the current frame.
seek(frame: int): voidSeeks to a specific frame index in the current sequence without changing playing state.
update(dt: float): voidAdvances animation time by dt seconds and updates the target node's texture region. Calling this yourself takes over stepping this player from the scene (see the stepping rule on the class).
onComplete(callback: Function): voidRegisters a callback invoked when a non-looping animation reaches its final frame.