File size: 1,315 Bytes
670a607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Physics } from "phaser";
export class Actor extends Physics.Arcade.Sprite {
  constructor(
    scene: Phaser.Scene,
    x: number,
    y: number,
    texture: string,
    frame?: string | number
  ) {
    super(scene, x, y, texture, frame);
    scene.add.existing(this);
    scene.physics.add.existing(this);
    this.getBody().setCollideWorldBounds(true);
  }

  protected getBody(): Physics.Arcade.Body {
    return this.body as Physics.Arcade.Body;
  }

  initAnimations(): void {
    this.scene.anims.create({
      key: this.name + "-walk-down",
      frames: this.scene.anims.generateFrameNumbers(this.name, {
        start: 0,
        end: 2,
      }),
      frameRate: 6,
    });
    this.scene.anims.create({
      key: this.name + "-walk-up",
      frames: this.scene.anims.generateFrameNumbers(this.name, {
        start: 3,
        end: 5,
      }),
      frameRate: 6,
    });
    this.scene.anims.create({
      key: this.name + "-walk-left",
      frames: this.scene.anims.generateFrameNumbers(this.name, {
        start: 6,
        end: 8,
      }),
      frameRate: 6,
    });
    this.scene.anims.create({
      key: this.name + "-walk-right",
      frames: this.scene.anims.generateFrameNumbers(this.name, {
        start: 9,
        end: 11,
      }),
      frameRate: 6,
    });
  }
}