aboutsummaryrefslogtreecommitdiffstats
path: root/src/Animation.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Animation.ts')
-rw-r--r--src/Animation.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Animation.ts b/src/Animation.ts
new file mode 100644
index 0000000..13adb6c
--- /dev/null
+++ b/src/Animation.ts
@@ -0,0 +1,23 @@
+import { ctx } from "./consts";
+import Drawable from "./Drawable";
+
+export default class Anime extends Drawable {
+ i = 0;
+ j = 0;
+
+ constructor(drawable: Drawable, public frames: string[]) {
+ super(drawable._x, drawable._y)
+ this.width = drawable.width
+ this.height = drawable.height
+ }
+
+ 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; }
+ return this.i !== this.frames.length;
+ }
+}
+