/
Sprite_StateOverlay.js
69 lines (59 loc) · 1.82 KB
/
Sprite_StateOverlay.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
//-----------------------------------------------------------------------------
// Sprite_StateOverlay
//
// The sprite for displaying an overlay image for a state.
function Sprite_StateOverlay() {
this.initialize.apply(this, arguments);
}
Sprite_StateOverlay.prototype = Object.create(Sprite_Base.prototype);
Sprite_StateOverlay.prototype.constructor = Sprite_StateOverlay;
Sprite_StateOverlay.prototype.initialize = function() {
Sprite_Base.prototype.initialize.call(this);
this.initMembers();
this.loadBitmap();
};
Sprite_StateOverlay.prototype.initMembers = function() {
this._battler = null;
this._overlayIndex = 0;
this._animationCount = 0;
this._pattern = 0;
this.anchor.x = 0.5;
this.anchor.y = 1;
};
Sprite_StateOverlay.prototype.loadBitmap = function() {
this.bitmap = ImageManager.loadSystem('States');
this.setFrame(0, 0, 0, 0);
};
Sprite_StateOverlay.prototype.setup = function(battler) {
this._battler = battler;
};
Sprite_StateOverlay.prototype.update = function() {
Sprite_Base.prototype.update.call(this);
this._animationCount++;
if (this._animationCount >= this.animationWait()) {
this.updatePattern();
this.updateFrame();
this._animationCount = 0;
}
};
Sprite_StateOverlay.prototype.animationWait = function() {
return 8;
};
Sprite_StateOverlay.prototype.updatePattern = function() {
this._pattern++;
this._pattern %= 8;
if (this._battler) {
this._overlayIndex = this._battler.stateOverlayIndex();
}
};
Sprite_StateOverlay.prototype.updateFrame = function() {
if (this._overlayIndex > 0) {
var w = 96;
var h = 96;
var sx = this._pattern * w;
var sy = (this._overlayIndex - 1) * h;
this.setFrame(sx, sy, w, h);
} else {
this.setFrame(0, 0, 0, 0);
}
};