-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSprite_Base.js
64 lines (54 loc) · 1.76 KB
/
Sprite_Base.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
55
56
57
58
59
60
61
62
63
64
//-----------------------------------------------------------------------------
// Sprite_Base
//
// The sprite class with a feature which displays animations.
function Sprite_Base() {
this.initialize.apply(this, arguments);
}
Sprite_Base.prototype = Object.create(Sprite.prototype);
Sprite_Base.prototype.constructor = Sprite_Base;
Sprite_Base.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this._animationSprites = [];
this._effectTarget = this;
this._hiding = false;
};
Sprite_Base.prototype.update = function() {
Sprite.prototype.update.call(this);
this.updateVisibility();
this.updateAnimationSprites();
};
Sprite_Base.prototype.hide = function() {
this._hiding = true;
this.updateVisibility();
};
Sprite_Base.prototype.show = function() {
this._hiding = false;
this.updateVisibility();
};
Sprite_Base.prototype.updateVisibility = function() {
this.visible = !this._hiding;
};
Sprite_Base.prototype.updateAnimationSprites = function() {
if (this._animationSprites.length > 0) {
var sprites = this._animationSprites.clone();
this._animationSprites = [];
for (var i = 0; i < sprites.length; i++) {
var sprite = sprites[i];
if (sprite.isPlaying()) {
this._animationSprites.push(sprite);
} else {
sprite.remove();
}
}
}
};
Sprite_Base.prototype.startAnimation = function(animation, mirror, delay) {
var sprite = new Sprite_Animation();
sprite.setup(this._effectTarget, animation, mirror, delay);
this.parent.addChild(sprite);
this._animationSprites.push(sprite);
};
Sprite_Base.prototype.isAnimationPlaying = function() {
return this._animationSprites.length > 0;
};