aboutsummaryrefslogtreecommitdiffstats
path: root/src/Animation.ts
blob: 13adb6ce0bbf7a9c308e1dfd6029cda1cc016849 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
  }
}