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
animations: Map<string, Animation> = ...
currentFrame: number = 0
currentTime: number = 0
playing: boolean = false
reset: boolean = false
speed: number = 1