diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-06-02 08:54:02 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-06-02 08:54:02 +0200 |
| commit | 6c37585ef4ef2535aff8c45c64850be0a6c26eab (patch) | |
| tree | c53e07505182735fbd23687a0c731d4bb2f10e14 /src/Animation.ts | |
| parent | 7a494b148dd03d6346a63641fc479015e7450a26 (diff) | |
| download | 1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.gz 1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.zst 1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.zip | |
Death animations
Diffstat (limited to 'src/Animation.ts')
| -rw-r--r-- | src/Animation.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Animation.ts b/src/Animation.ts index 820a6dd..968a57d 100644 --- a/src/Animation.ts +++ b/src/Animation.ts @@ -5,21 +5,25 @@ export default class Anime extends Drawable { i = 0; j = 0; - constructor(drawable: Drawable, public frames: Array<string | HTMLImageElement>) { + constructor(public drawable: Drawable, public frames: Array<string | HTMLImageElement>) { super(drawable._x, drawable._y) this.width = drawable.width this.height = drawable.height - if (frames.length === 0) debugger + // if (frames.length === 0) debugger } draw(): boolean { if (typeof this.frames[0] === "string") { ctx.fillStyle = (this.frames as string[])[this.i]; - ctx.fillRect(this.x, this.y, this.width, this.height); + ctx.fillRect(this.drawable.x, this.drawable.y, this.drawable.width, this.drawable.height); } else { - ctx.drawImage((this.frames as HTMLImageElement[])[this.i], this.x, this.y) + try { + const f = (this.frames as HTMLImageElement[])[this.i] + if (f) + ctx.drawImage(f, this.drawable.x, this.drawable.y) + } catch (e) { debugger } } - if (++this.j === 4) { this.i++; this.j = 0; } + if (++this.j === 5) { this.i++; this.j = 0; } return this.i !== this.frames.length; } } |
