From 2f8b8c87fb2062313afea7b625ccb20d1bea95b9 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 24 May 2022 18:25:43 +0200 Subject: Initial commit --- src/Animation.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Animation.ts (limited to 'src/Animation.ts') 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; + } +} + -- cgit v1.3.1