Skip to content

Commit 6fe063b

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 63a614e + b981f62 commit 6fe063b

23 files changed

Lines changed: 482 additions & 231 deletions

v3/src/animation/AnimationManager.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var AnimationManager = function (game)
2626

2727
this.textureManager = null;
2828

29+
this.globalTimeScale = 1;
30+
2931
this.anims = new Map();
3032
};
3133

@@ -126,6 +128,52 @@ AnimationManager.prototype = {
126128
return child;
127129
},
128130

131+
play: function (key, child)
132+
{
133+
if (!Array.isArray(child))
134+
{
135+
child = [ child ];
136+
}
137+
138+
var anim = this.get(key);
139+
140+
if (!anim)
141+
{
142+
return;
143+
}
144+
145+
for (var i = 0; i < child.length; i++)
146+
{
147+
child[i].anims.play(key);
148+
}
149+
150+
return this;
151+
},
152+
153+
staggerPlay: function (key, child, stagger)
154+
{
155+
if (stagger === undefined) { stagger = 0; }
156+
157+
if (!Array.isArray(child))
158+
{
159+
child = [ child ];
160+
}
161+
162+
var anim = this.get(key);
163+
164+
if (!anim)
165+
{
166+
return;
167+
}
168+
169+
for (var i = 0; i < child.length; i++)
170+
{
171+
child[i].anims.delayedPlay(stagger * i, key);
172+
}
173+
174+
return this;
175+
},
176+
129177
generateFrameNumbers: function (key, config)
130178
{
131179
var startFrame = GetObjectValue(config, 'start', 0);

v3/src/animation/frame/Animation.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ var Animation = function (manager, key, config)
1111
this.frames = GetFrames(manager.textureManager, GetObjectValue(config, 'frames', []));
1212

1313
// The frame rate of playback in frames per second (default 24 if duration is null)
14-
this.framerate = GetObjectValue(config, 'framerate', null);
14+
this.frameRate = GetObjectValue(config, 'framerate', null);
1515

16-
// How long the animation should play for. If framerate is set it overrides this value
17-
// otherwise framerate is derived from duration
16+
// How long the animation should play for. If frameRate is set it overrides this value
17+
// otherwise frameRate is derived from duration
1818
this.duration = GetObjectValue(config, 'duration', null);
1919

20-
if (this.duration === null && this.framerate === null)
20+
if (this.duration === null && this.frameRate === null)
2121
{
22-
this.framerate = 24;
23-
this.duration = this.framerate / this.frames.length;
22+
this.frameRate = 24;
23+
this.duration = this.frameRate / this.frames.length;
2424
}
25-
else if (this.duration && this.framerate === null)
25+
else if (this.duration && this.frameRate === null)
2626
{
27-
// Duration given but no framerate, so set the framerate based on duration
27+
// Duration given but no frameRate, so set the frameRate based on duration
2828
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
29-
// So framerate is 12 / 4 = 3 fps
30-
this.framerate = this.frames.length / this.duration;
29+
// So frameRate is 12 / 4 = 3 fps
30+
this.frameRate = this.frames.length / this.duration;
3131
}
3232
else
3333
{
34-
// No duration, so derive from the framerate
35-
// I.e. 15 frames in the animation, framerate = 30 fps
34+
// No duration, so derive from the frameRate
35+
// I.e. 15 frames in the animation, frameRate = 30 fps
3636
// So duration is 15 / 30 = 0.5 (half a second)
37-
this.duration = this.frames.length / this.framerate;
37+
this.duration = this.frames.length / this.frameRate;
3838
}
3939

4040
// ms per frame (without including frame specific modifiers)
41-
this.msPerFrame = 1000 / this.framerate;
41+
this.msPerFrame = 1000 / this.frameRate;
4242

4343
// Skip frames if the time lags, or always advanced anyway?
4444
this.skipMissedFrames = GetObjectValue(config, 'skipMissedFrames', true);
@@ -73,7 +73,21 @@ Animation.prototype = {
7373
startFrame = 0;
7474
}
7575

76-
component.updateAnimation(this);
76+
if (component.currentAnim !== this)
77+
{
78+
component.currentAnim = this;
79+
80+
component._timeScale = 1;
81+
component.frameRate = this.frameRate;
82+
component.duration = this.duration;
83+
component.msPerFrame = this.msPerFrame;
84+
component.skipMissedFrames = this.skipMissedFrames;
85+
component._delay = this.delay;
86+
component._repeat = this.repeat;
87+
component._repeatDelay = this.repeatDelay;
88+
component._yoyo = this.yoyo;
89+
}
90+
7791
component.updateFrame(this.frames[startFrame]);
7892
},
7993

@@ -88,19 +102,19 @@ Animation.prototype = {
88102

89103
// When is the first update due?
90104
component.accumulator = 0;
91-
component.nextTick = this.msPerFrame + component.currentFrame.duration;
105+
component.nextTick = component.msPerFrame + component.currentFrame.duration;
92106

93107
if (includeDelay)
94108
{
95-
component.nextTick += (this.delay * 1000);
109+
component.nextTick += (component._delay * 1000);
96110
}
97111
},
98112

99113
getNextTick: function (component)
100114
{
101115
// When is the next update due?
102116
component.accumulator -= component.nextTick;
103-
component.nextTick = this.msPerFrame + component.currentFrame.duration;
117+
component.nextTick = component.msPerFrame + component.currentFrame.duration;
104118
},
105119

106120
nextFrame: function (component)
@@ -117,6 +131,8 @@ Animation.prototype = {
117131
if (this.yoyo)
118132
{
119133
component.forward = false;
134+
135+
component.updateFrame(frame.prevFrame);
120136

121137
// Delay for the current frame
122138
this.getNextTick(component);
@@ -171,11 +187,11 @@ Animation.prototype = {
171187

172188
repeatAnimation: function (component)
173189
{
174-
if (this.repeatDelay > 0 && component.pendingRepeat === false)
190+
if (component._repeatDelay > 0 && component.pendingRepeat === false)
175191
{
176192
component.pendingRepeat = true;
177193
component.accumulator -= component.nextTick;
178-
component.nextTick += (this.repeatDelay * 1000);
194+
component.nextTick += (component._repeatDelay * 1000);
179195
}
180196
else
181197
{

v3/src/animation/frame/Delay.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Gets or sets the amount of time in seconds between repeats.
2+
// For example, if repeat is 2 and repeatDelay is 1, the animation will play initially,
3+
// then wait for 1 second before it repeats, then play again, then wait 1 second again
4+
// before doing its final repeat.
5+
6+
var Delay = function (value)
7+
{
8+
if (value === undefined)
9+
{
10+
return this._delay;
11+
}
12+
else
13+
{
14+
this._delay = value;
15+
16+
return this;
17+
}
18+
};
19+
20+
module.exports = Delay;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var DelayedPlay = function (delay, key, startFrame)
2+
{
3+
this.play(key, startFrame);
4+
5+
this.nextTick += (delay * 1000);
6+
7+
return this;
8+
};
9+
10+
module.exports = DelayedPlay;

v3/src/animation/frame/Load.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var Load = function (key, startFrame)
2+
{
3+
if (startFrame === undefined) { startFrame = 0; }
4+
5+
if (this.isPlaying)
6+
{
7+
this.stop();
8+
}
9+
10+
// Load the new animation in
11+
this.animationManager.load(this, key, startFrame);
12+
13+
return this;
14+
};
15+
16+
module.exports = Load;

v3/src/animation/frame/Pause.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var Pause = function (atFrame)
2+
{
3+
if (!this._paused)
4+
{
5+
this._paused = true;
6+
this._wasPlaying = this.isPlaying;
7+
this.isPlaying = false;
8+
}
9+
10+
if (atFrame !== undefined)
11+
{
12+
this.updateFrame(atFrame);
13+
}
14+
15+
return this;
16+
};
17+
18+
module.exports = Pause;

v3/src/animation/frame/Paused.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var Paused = function (value)
2+
{
3+
if (value !== undefined)
4+
{
5+
// Setter
6+
if (value)
7+
{
8+
return this.pause();
9+
}
10+
else
11+
{
12+
return this.resume();
13+
}
14+
}
15+
else
16+
{
17+
return this._paused;
18+
}
19+
};
20+
21+
module.exports = Paused;

v3/src/animation/frame/Play.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var Play = function (key, startFrame)
2+
{
3+
if (startFrame === undefined) { startFrame = 0; }
4+
5+
this.load(key, startFrame);
6+
7+
// Should give us 9,007,199,254,740,991 safe repeats
8+
this.repeatCounter = (this._repeat === -1) ? Number.MAX_SAFE_INTEGER : this._repeat;
9+
10+
this.currentAnim.getFirstTick(this);
11+
12+
this.forward = true;
13+
this.isPlaying = true;
14+
this.pendingRepeat = false;
15+
16+
this.prevTick = this.mainloop.lastFrameTimeMs;
17+
18+
return this;
19+
};
20+
21+
module.exports = Play;

v3/src/animation/frame/Progress.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Value between 0 and 1. How far this animation is through, ignoring repeats and yoyos.
2+
// If the animation has a non-zero repeat defined, progress and totalProgress will be different
3+
// because progress doesn't include any repeats or repeatDelays whereas totalProgress does.
4+
var Progress = function (value)
5+
{
6+
if (value === undefined)
7+
{
8+
var p = this.currentFrame.progress;
9+
10+
if (!this.forward)
11+
{
12+
p = 1 - p;
13+
}
14+
15+
return p;
16+
}
17+
else
18+
{
19+
// TODO: Set progress
20+
21+
return this;
22+
}
23+
};
24+
25+
module.exports = Progress;

v3/src/animation/frame/Repeat.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Gets or sets the number of times that the animation should repeat
2+
// after its first iteration. For example, if repeat is 1, the animation will
3+
// play a total of twice (the initial play plus 1 repeat).
4+
// To repeat indefinitely, use -1. repeat should always be an integer.
5+
6+
var Repeat = function (value)
7+
{
8+
if (value === undefined)
9+
{
10+
return this._repeat;
11+
}
12+
else
13+
{
14+
this._repeat = value;
15+
this.repeatCounter = 0;
16+
17+
return this;
18+
}
19+
};
20+
21+
module.exports = Repeat;

0 commit comments

Comments
 (0)