diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-05-24 18:25:43 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-05-24 18:25:43 +0200 |
| commit | 2f8b8c87fb2062313afea7b625ccb20d1bea95b9 (patch) | |
| tree | 973e20986e4b9279b9322a9fd140e6f989eaf492 /src/Animation.ts | |
| download | 1942-2f8b8c87fb2062313afea7b625ccb20d1bea95b9.tar.gz 1942-2f8b8c87fb2062313afea7b625ccb20d1bea95b9.tar.zst 1942-2f8b8c87fb2062313afea7b625ccb20d1bea95b9.zip | |
Initial commit
Diffstat (limited to 'src/Animation.ts')
| -rw-r--r-- | src/Animation.ts | 23 |
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; + } +} + |
