/
Sprite_StateIcon.js
77 lines (66 loc) · 2.05 KB
/
Sprite_StateIcon.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
65
66
67
68
69
70
71
72
73
74
75
76
77
//-----------------------------------------------------------------------------
// Sprite_StateIcon
//
// The sprite for displaying state icons.
function Sprite_StateIcon() {
this.initialize.apply(this, arguments);
}
Sprite_StateIcon.prototype = Object.create(Sprite.prototype);
Sprite_StateIcon.prototype.constructor = Sprite_StateIcon;
Sprite_StateIcon.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this.initMembers();
this.loadBitmap();
};
Sprite_StateIcon._iconWidth = 32;
Sprite_StateIcon._iconHeight = 32;
Sprite_StateIcon.prototype.initMembers = function() {
this._battler = null;
this._iconIndex = 0;
this._animationCount = 0;
this._animationIndex = 0;
this.anchor.x = 0.5;
this.anchor.y = 0.5;
};
Sprite_StateIcon.prototype.loadBitmap = function() {
this.bitmap = ImageManager.loadSystem('IconSet');
this.setFrame(0, 0, 0, 0);
};
Sprite_StateIcon.prototype.setup = function(battler) {
this._battler = battler;
};
Sprite_StateIcon.prototype.update = function() {
Sprite.prototype.update.call(this);
this._animationCount++;
if (this._animationCount >= this.animationWait()) {
this.updateIcon();
this.updateFrame();
this._animationCount = 0;
}
};
Sprite_StateIcon.prototype.animationWait = function() {
return 40;
};
Sprite_StateIcon.prototype.updateIcon = function() {
var icons = [];
if (this._battler && this._battler.isAlive()) {
icons = this._battler.allIcons();
}
if (icons.length > 0) {
this._animationIndex++;
if (this._animationIndex >= icons.length) {
this._animationIndex = 0;
}
this._iconIndex = icons[this._animationIndex];
} else {
this._animationIndex = 0;
this._iconIndex = 0;
}
};
Sprite_StateIcon.prototype.updateFrame = function() {
var pw = Sprite_StateIcon._iconWidth;
var ph = Sprite_StateIcon._iconHeight;
var sx = this._iconIndex % 16 * pw;
var sy = Math.floor(this._iconIndex / 16) * ph;
this.setFrame(sx, sy, pw, ph);
};