作る

SpriteAnimator

Utility that tracks sprite sheet animation state and draws frames on a canvas.

SpriteAnimator

Utility that tracks sprite sheet animation state and draws frames on a canvas.

Examples

const animator = new SpriteAnimator({
  image,
  frameWidth: 64,
  frameHeight: 64,
  frameCount: 8,
  fps: 10,
});
 
function render(dt: number) {
  animator.update(dt);
  animator.draw(ctx, player.x, player.y);
}

Members

update

update(dt: number): void

Advances the internal frame timer based on elapsed milliseconds.

draw

draw(ctx: CanvasRenderingContext2D, x: number, y: number): void

Draws the current frame at the specified canvas coordinates.

reset

reset(): void

Resets to the first frame. Useful when restarting an animation.