Some animations

This commit is contained in:
kolaflash
2025-12-01 19:21:57 +01:00
parent ad9ab70d05
commit bc83534826
4 changed files with 79 additions and 42 deletions
+8 -8
View File
@@ -4,8 +4,6 @@ export type Sprite = {
yFrames: number;
frameWidth: number;
frameHeight: number;
xIndex: number;
yIndex: number;
};
export function createSprite(
@@ -19,26 +17,28 @@ export function createSprite(
yFrames,
frameWidth: image.width / xFrames,
frameHeight: image.height / yFrames,
xIndex: 0,
yIndex: 0,
};
}
export function drawSprite(
ctx: CanvasRenderingContext2D,
sprite: Sprite,
xIndex: number,
yIndex: number,
x: number,
y: number,
width?: number,
height?: number,
): void {
ctx.drawImage(
sprite.image,
sprite.xIndex * sprite.frameWidth,
sprite.yIndex * sprite.frameHeight,
xIndex * sprite.frameWidth,
yIndex * sprite.frameHeight,
sprite.frameWidth,
sprite.frameHeight,
x,
y,
sprite.frameWidth,
sprite.frameHeight,
width || sprite.frameWidth,
height || sprite.frameHeight,
);
}