Animation class used to configure sprite animations. It defines properties like the source image(s), slice dimensions for sprite sheets, frame sequence, playback speed and looping behavior.

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

Constructors

Properties

fps: number = 12
frames: number[] = []
image:
    | string
    | string[]
    | HTMLImageElement
    | HTMLImageElement[]
loop: boolean = false
slice: AnimationSlice = ...