From 0010f2de57cfa97106432ea1849c1bb75d3d99a1 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 31 May 2022 18:11:09 +0200 Subject: All enemies movement --- src/Animation.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Animation.ts') diff --git a/src/Animation.ts b/src/Animation.ts index 13adb6c..820a6dd 100644 --- a/src/Animation.ts +++ b/src/Animation.ts @@ -5,18 +5,21 @@ export default class Anime extends Drawable { i = 0; j = 0; - constructor(drawable: Drawable, public frames: string[]) { + constructor(drawable: Drawable, public frames: Array) { super(drawable._x, drawable._y) this.width = drawable.width this.height = drawable.height + if (frames.length === 0) debugger } draw(): boolean { - // console.log("drawing", this) - ctx.fillStyle = this.frames[this.i]; - ctx.fillRect(this.x, this.y, this.width, this.height); - this.j++; - if (this.j === 50) { this.i++; this.j = 0; } + if (typeof this.frames[0] === "string") { + ctx.fillStyle = (this.frames as string[])[this.i]; + ctx.fillRect(this.x, this.y, this.width, this.height); + } else { + ctx.drawImage((this.frames as HTMLImageElement[])[this.i], this.x, this.y) + } + if (++this.j === 4) { this.i++; this.j = 0; } return this.i !== this.frames.length; } } -- cgit v1.3.1