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): voidAdvances the internal frame timer based on elapsed milliseconds.
draw
draw(ctx: CanvasRenderingContext2D, x: number, y: number): voidDraws the current frame at the specified canvas coordinates.
reset
reset(): voidResets to the first frame. Useful when restarting an animation.