AnimationPlayer
Frame-by-frame sprite animation.
ts
import { AnimationSequence, AnimationPlayer } from "willow";AnimationSequence
ts
class AnimationSequenceDefines 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
| Member | Description |
|---|---|
name: string | Name of this animation sequence (e.g. "idle", "walk", "jump"). |
frames: Array<TextureRegion> | Array of texture regions representing each frame in order. |
fps: float | Playback speed in frames per second (default 10.0). |
loop: boolean | When true, wraps back to frame 0 after the last frame; otherwise stops at the final frame. |
AnimationPlayer
ts
class AnimationPlayerManages 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
| Member | Description |
|---|---|
readonly current: string | Name of the currently active sequence, or empty string if none. |
readonly frame: int | Zero-based index of the current frame within the active sequence. |
readonly isPlaying: boolean | True while an animation sequence is actively playing. |
AnimationPlayer: methods
| Member | Description |
|---|---|
addSequence(seq: AnimationSequence): void | Registers a named animation sequence with this player. |
play(name: string): void | Starts playing the named sequence from frame 0. No-op if already playing it. |
playFrom(name: string, frame: int): void | Starts playing the named sequence from a specific frame index. |
stop(): void | Pauses or stops playback at the current frame. |
seek(frame: int): void | Seeks to a specific frame index in the current sequence without changing playing state. |
update(dt: float): void | Advances 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): void | Registers a callback invoked when a non-looping animation reaches its final frame. |