forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.js
More file actions
85 lines (63 loc) · 1.66 KB
/
Copy pathAnimation.js
File metadata and controls
85 lines (63 loc) · 1.66 KB
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
78
79
80
81
82
83
84
85
/**
* The Animation Component.
* Should be as small as possible, really just playhead info.
*
* @class
*/
var Animation = function (parent)
{
// Sprite / Game Object
this.parent = parent;
this.animationManager = parent.state.sys.anims;
this.isPlaying = false;
// Reference to the Phaser.Animation object
this.currentAnim = null;
// Reference to the Phaser.AnimationFrame object
this.currentFrame = null;
// Timing playhead values
this.accumulator = 0;
this.nextTick = 0;
};
Animation.prototype.constructor = Animation;
Animation.prototype = {
load: function (key, startFrame)
{
if (startFrame === undefined) { startFrame = 0; }
if (this.isPlaying)
{
this.stop();
}
// Load the new animation in
this.animationManager.load(this, key, startFrame);
this.updateFrame();
},
play: function (key, startFrame)
{
if (startFrame === undefined) { startFrame = 0; }
this.load(key, startFrame);
this.accumulator = 0;
this.currentAnim.getNextTick(this);
this.isPlaying = true;
},
stop: function ()
{
this.isPlaying = false;
},
updateFrame: function ()
{
this.parent.texture = this.currentFrame.frame.texture;
this.parent.frame = this.currentFrame.frame;
},
update: function (timestamp, frameDelta)
{
if (this.isPlaying)
{
this.accumulator += frameDelta;
if (this.accumulator >= this.nextTick)
{
this.currentAnim.setFrame(this);
}
}
}
};
module.exports = Animation;