The Animator component manages sprite animations. It holds a map of named animations and controls which animation is currently playing, its speed, and playback state.

const walkAnimation = new Animation({
image: "walk.png",
slice: { size: new Vector2(32, 32) },
frames: [0, 1, 2, 3, 4, 5],
fps: 12,
loop: true
});

const idleAnimation = new Animation({
image: "idle.png",
slice: { size: new Vector2(32, 32) },
frames: [6, 7, 8, 9],
fps: 8,
loop: true
});

const animator = new Animator({
animations: new Map([
["walk", walkAnimation],
["idle", idleAnimation]
]),
animation: "idle",
speed: 1,
playing: true
});

Constructors

Properties

animation: string

The animation to play.

animations: Map<string, Animation> = ...

The animations to play.

currentFrame: number = 0

The current frame of the animation.

currentTime: number = 0

The current time of the animation.

ignoreTimeScale: boolean = false

TRUE If the animation should ignore the time scale, FALSE otherwise.

playing: boolean = false

TRUE If the animation is playing, FALSE otherwise.

reset: boolean = false

TRUE If the animation should reset to the first frame when the animation is stopped, FALSE otherwise.

speed: number = 1

The speed of the animation.