aboutsummaryrefslogtreecommitdiffstats
path: root/src/Animation.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-05-31 18:11:09 +0200
committerMaksymilian Jopek <maks@jopek.eu>2022-05-31 18:11:09 +0200
commit0010f2de57cfa97106432ea1849c1bb75d3d99a1 (patch)
tree41e89ff13aacfc4dc1324a365302a0867e316dc9 /src/Animation.ts
parent344737031e5bbad5f24469aabf45be6535c893f3 (diff)
download1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz
1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst
1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip
All enemies movement
Diffstat (limited to 'src/Animation.ts')
-rw-r--r--src/Animation.ts15
1 files changed, 9 insertions, 6 deletions
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<string | HTMLImageElement>) {
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;
}
}