-
Notifications
You must be signed in to change notification settings - Fork 1
/
Steve.js
54 lines (41 loc) · 1.55 KB
/
Steve.js
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
class MultiAnimatedSprite extends PIXI.extras.AnimatedSprite {
constructor(arg, states) {
// states = { "state1": {states: [1,2,3,2,1], loop: true, sizes: {width, height}}, "state2": {...}, ... }
super(arg);
this._scaleCf = 1;
this.allStates = arg;
this.animations = states ? states : {};
this.type = "main";
this.scale.x = this.scale.y = 0.25*this.scaleCf;
// this.width = this.allStates[0].orig.
this.playAnimation("default");
}
get scaleCf(){
return this._scaleCf;
}
set scaleCf(value) {
this.scaleX *= value / this._scaleCf;
this.scaleY *= value / this._scaleCf;
this._scaleCf = value;
}
playAnimation(animationName) {
if (!game.on) {return;}
this.animationName = animationName;
if (this.isDefault && animationName !== "default") { this.isDefault = false; }
if (!this.isDefault && animationName === "default") { this.isDefault = true; }
if (!animationName) { this.play(); return; }
let textures = [];
for (let state of this.animations[animationName].states) { textures.push(this.allStates[state]); }
this.loop = this.animations[animationName].loop;
this._textures = textures;
this.scale.x = this.scale.y = this.animations[animationName].scale *this.scaleCf;
this.stop();
this.gotoAndPlay(0);
}
toDefault() {
if (!this.isDefault) {
console.log("def");
this.playAnimation("default");
}
}
}