From 6c37585ef4ef2535aff8c45c64850be0a6c26eab Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Thu, 2 Jun 2022 08:54:02 +0200 Subject: Death animations --- src/Animation.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/Animation.ts') 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) { + constructor(public drawable: Drawable, public frames: Array) { 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; } } -- cgit v1.3.1