Skip to content

Commit eafb488

Browse files
committed
Merge branch 'master' into containers
2 parents 96b8db4 + fa23202 commit eafb488

7 files changed

Lines changed: 324 additions & 247 deletions

File tree

CHANGELOG.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,51 @@ being passed to the simulation. The default value is 1 to remain consistent with
4949
* The ComputedSize Component now has `setSize` and `setDisplaySize` methods. This component is used for Game Objects that have a non-texture based size.
5050
* The GamepadManager now extends EventEmitter directly, just like the KeyboardManager does.
5151
* The Gamepad Axis threshold has been increased from 0.05 to 0.1.
52-
* Animation.updateFrame will now call `setSizeToFrame` on the Game Object, which will adjust the Game Objects `width` and `height` properties to match the frame size. Fix #3473 (thanks @wtravO @jp-gc)
53-
* Animation.updateFrame now supports animation frames with custom pivot points and injects these into the Game Object origin.
5452

55-
Also, my thanks to the following for helping with the Phaser 3 Examples and Docs, either by reporting errors, fixing them or helping author the docs: @gabegordon @melissaelopez @samid737 @nbs @tgrajewski @pagesrichie @hexus @mbrickn @erd0s @icbat @Matthew-Herman
53+
### Animation Component Updates
54+
55+
We have refactored the Animation API to make it more consistent with the rest of Phaser 3 and to fix some issues. All of the following changes apply to the Animation Component:
56+
57+
* Animation durations, delays and repeatDelays are all now specified in milliseconds, not seconds like before. This makes them consistent with Tweens, Sounds and other parts of v3. You can still use the `frameRate` property to set the speed of an animation in frames per second.
58+
* `delay` method has been removed.
59+
* `setDelay` allows you to define the delay before playback begins.
60+
* `getDelay` returns the animation playback delay value.
61+
* `delayedPlay` now returns the parent Game Object instead of the component.
62+
* `load` now returns the parent Game Object instead of the component.
63+
* `pause` now returns the parent Game Object instead of the component.
64+
* `resume` now returns the parent Game Object instead of the component.
65+
* `isPaused` returns a boolean indicating the paused state of the animation.
66+
* `paused` method has been removed.
67+
* `play` now returns the parent Game Object instead of the component.
68+
* `progress` method has been removed.
69+
* `getProgress` returns the animation progress value.
70+
* `repeat` method has been removed.
71+
* `getRepeat` returns the animation repeat value.
72+
* `setRepeat` sets the number of times the current animation will repeat.
73+
* `repeatDelay` method has been removed.
74+
* `getRepeatDelay` returns the animation repeat delay value.
75+
* `setRepeatDelay` sets the delay time between each repeat.
76+
* `restart` now returns the parent Game Object instead of the component.
77+
* `stop` now returns the parent Game Object instead of the component.
78+
* `timeScale` method has been removed.
79+
* `getTimeScale` returns the animation time scale value.
80+
* `setTimeScale` sets the time scale value.
81+
* `totalFrames` method has been removed.
82+
* `getTotalFrames` returns the total number of frames in the animation.
83+
* `totalProgres` method has been removed as it did nothing and was mis-spelt.
84+
* `yoyo` method has been removed.
85+
* `getYoyo` returns if the animation will yoyo or not.
86+
* `setYoyo` sets if the animation will yoyo or not.
87+
* `updateFrame` will now call `setSizeToFrame` on the Game Object, which will adjust the Game Objects `width` and `height` properties to match the frame size. Fix #3473 (thanks @wtravO @jp-gc)
88+
* `updateFrame` now supports animation frames with custom pivot points and injects these into the Game Object origin.
89+
* `destroy` now removes events, references to the Animation Manager and parent Game Object, clears the current animation and frame and empties internal arrays.
90+
* Changing the `yoyo` property on an Animation Component would have no effect as it only ever checked the global property, it now checks the local one properly allowing you to specify a `yoyo` on a per Game Object basis.
91+
92+
### Examples, Documentation and TypeScript
93+
94+
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
95+
96+
@gabegordon @melissaelopez @samid737 @nbs @tgrajewski @pagesrichie @hexus @mbrickn @erd0s @icbat @Matthew-Herman
5697

5798

5899

src/animations/Animation.js

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ var GetValue = require('../utils/object/GetValue');
1515
* @property {string} type - A frame based animation (as opposed to a bone based animation)
1616
* @property {JSONAnimationFrame[]} frames - [description]
1717
* @property {integer} frameRate - The frame rate of playback in frames per second (default 24 if duration is null)
18-
* @property {integer} duration - How long the animation should play for.
18+
* @property {integer} duration - How long the animation should play for in milliseconds. If not given its derived from frameRate.
1919
* @property {boolean} skipMissedFrames - Skip frames if the time lags, or always advanced anyway?
20-
* @property {integer} delay - Delay before starting playback (in seconds)
20+
* @property {integer} delay - Delay before starting playback. Value given in milliseconds.
2121
* @property {integer} repeat - Number of times to repeat the animation (-1 for infinity)
22-
* @property {integer} repeatDelay - Delay before the repeat starts (in seconds)
22+
* @property {integer} repeatDelay - Delay before the animation repeats. Value given in milliseconds.
2323
* @property {boolean} yoyo - Should the animation yoyo? (reverse back down to the start) before repeating?
2424
* @property {boolean} showOnStart - Should sprite.visible = true when the animation starts to play?
2525
* @property {boolean} hideOnComplete - Should sprite.visible = false when the animation finishes?
@@ -41,14 +41,15 @@ var GetValue = require('../utils/object/GetValue');
4141
* @property {AnimationFrameConfig[]} [frames] - [description]
4242
* @property {string} [defaultTextureKey=null] - [description]
4343
* @property {integer} [frameRate] - The frame rate of playback in frames per second (default 24 if duration is null)
44-
* @property {integer} [duration] - How long the animation should play for.
44+
* @property {integer} [duration] - How long the animation should play for in milliseconds. If not given its derived from frameRate.
4545
* @property {boolean} [skipMissedFrames=true] - Skip frames if the time lags, or always advanced anyway?
46-
* @property {integer} [delay=0] - Delay before starting playback (in seconds)
46+
* @property {integer} [delay=0] - Delay before starting playback. Value given in milliseconds.
4747
* @property {integer} [repeat=0] - Number of times to repeat the animation (-1 for infinity)
48-
* @property {integer} [repeatDelay=0] - Delay before the repeat starts (in seconds)
48+
* @property {integer} [repeatDelay=0] - Delay before the animation repeats. Value given in milliseconds.
4949
* @property {boolean} [yoyo=false] - Should the animation yoyo? (reverse back down to the start) before repeating?
5050
* @property {boolean} [showOnStart=false] - Should sprite.visible = true when the animation starts to play?
5151
* @property {boolean} [hideOnComplete=false] - Should sprite.visible = false when the animation finishes?
52+
5253
* @property {*} [callbackScope] - [description]
5354
* @property {(false|function)} [onStart=false] - [description]
5455
* @property {Array.<*>} [onStartParams] - [description]
@@ -137,8 +138,9 @@ var Animation = new Class({
137138
this.frameRate = GetValue(config, 'frameRate', null);
138139

139140
/**
140-
* How long the animation should play for.
141-
* If frameRate is set it overrides this value otherwise frameRate is derived from duration.
141+
* How long the animation should play for, in milliseconds.
142+
* If the `frameRate` property has been set then it overrides this value,
143+
* otherwise the `frameRate` is derived from `duration`.
142144
*
143145
* @name Phaser.Animations.Animation#duration
144146
* @type {integer}
@@ -150,25 +152,25 @@ var Animation = new Class({
150152
{
151153
// No duration or frameRate given, use default frameRate of 24fps
152154
this.frameRate = 24;
153-
this.duration = this.frameRate / this.frames.length;
155+
this.duration = (this.frameRate / this.frames.length) * 1000;
154156
}
155157
else if (this.duration && this.frameRate === null)
156158
{
157159
// Duration given but no frameRate, so set the frameRate based on duration
158-
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
159-
// So frameRate is 12 / 4 = 3 fps
160-
this.frameRate = this.frames.length / this.duration;
160+
// I.e. 12 frames in the animation, duration = 4000 ms
161+
// So frameRate is 12 / (4000 / 1000) = 3 fps
162+
this.frameRate = this.frames.length / (this.duration / 1000);
161163
}
162164
else
163165
{
164166
// frameRate given, derive duration from it (even if duration also specified)
165167
// I.e. 15 frames in the animation, frameRate = 30 fps
166-
// So duration is 15 / 30 = 0.5 (half a second)
167-
this.duration = this.frames.length / this.frameRate;
168+
// So duration is 15 / 30 = 0.5 * 1000 (half a second, or 500ms)
169+
this.duration = (this.frames.length / this.frameRate) * 1000;
168170
}
169171

170172
/**
171-
* ms per frame (without including frame specific modifiers)
173+
* How many ms per frame, not including frame specific modifiers.
172174
*
173175
* @name Phaser.Animations.Animation#msPerFrame
174176
* @type {integer}
@@ -187,7 +189,7 @@ var Animation = new Class({
187189
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
188190

189191
/**
190-
* Delay before starting playback (in seconds)
192+
* The delay in ms before the playback will begin.
191193
*
192194
* @name Phaser.Animations.Animation#delay
193195
* @type {integer}
@@ -197,7 +199,7 @@ var Animation = new Class({
197199
this.delay = GetValue(config, 'delay', 0);
198200

199201
/**
200-
* Number of times to repeat the animation (-1 for infinity)
202+
* Number of times to repeat the animation. Set to -1 to repeat forever.
201203
*
202204
* @name Phaser.Animations.Animation#repeat
203205
* @type {integer}
@@ -207,7 +209,7 @@ var Animation = new Class({
207209
this.repeat = GetValue(config, 'repeat', 0);
208210

209211
/**
210-
* Delay before the repeat starts (in seconds)
212+
* The delay in ms before the a repeat playthrough starts.
211213
*
212214
* @name Phaser.Animations.Animation#repeatDelay
213215
* @type {integer}
@@ -329,7 +331,7 @@ var Animation = new Class({
329331
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
330332

331333
/**
332-
* Global pause, effects all Game Objects using this Animation instance
334+
* Global pause. All Game Objects using this Animation instance are impacted by this property.
333335
*
334336
* @name Phaser.Animations.Animation#paused
335337
* @type {boolean}
@@ -342,10 +344,8 @@ var Animation = new Class({
342344
this.manager.on('resumeall', this.resume.bind(this));
343345
},
344346

345-
// Add frames to the end of the animation
346-
347347
/**
348-
* [description]
348+
* Add frames to the end of the animation.
349349
*
350350
* @method Phaser.Animations.Animation#addFrame
351351
* @since 3.0.0
@@ -359,10 +359,8 @@ var Animation = new Class({
359359
return this.addFrameAt(this.frames.length, config);
360360
},
361361

362-
// Add frame/s into the animation
363-
364362
/**
365-
* [description]
363+
* Add frame/s into the animation.
366364
*
367365
* @method Phaser.Animations.Animation#addFrameAt
368366
* @since 3.0.0
@@ -401,24 +399,25 @@ var Animation = new Class({
401399
},
402400

403401
/**
404-
* [description]
402+
* Check if the given frame index is valid.
405403
*
406404
* @method Phaser.Animations.Animation#checkFrame
407405
* @since 3.0.0
408406
*
409-
* @param {integer} index - [description]
407+
* @param {integer} index - The index to be checked.
410408
*
411-
* @return {boolean} [description]
409+
* @return {boolean} `true` if the index is valid, otherwise `false`.
412410
*/
413411
checkFrame: function (index)
414412
{
415-
return (index < this.frames.length);
413+
return (index >= 0 && index < this.frames.length);
416414
},
417415

418416
/**
419417
* [description]
420418
*
421419
* @method Phaser.Animations.Animation#completeAnimation
420+
* @protected
422421
* @since 3.0.0
423422
*
424423
* @param {Phaser.GameObjects.Components.Animation} component - [description]
@@ -437,6 +436,7 @@ var Animation = new Class({
437436
* [description]
438437
*
439438
* @method Phaser.Animations.Animation#getFirstTick
439+
* @protected
440440
* @since 3.0.0
441441
*
442442
* @param {Phaser.GameObjects.Components.Animation} component - [description]
@@ -452,14 +452,15 @@ var Animation = new Class({
452452

453453
if (includeDelay)
454454
{
455-
component.nextTick += (component._delay * 1000);
455+
component.nextTick += component._delay;
456456
}
457457
},
458458

459459
/**
460460
* [description]
461461
*
462462
* @method Phaser.Animations.Animation#getFrameAt
463+
* @protected
463464
* @since 3.0.0
464465
*
465466
* @param {integer} index - [description]
@@ -594,9 +595,10 @@ var Animation = new Class({
594595
},
595596

596597
/**
597-
* [description]
598+
* Loads the Animation values into the Animation Component.
598599
*
599600
* @method Phaser.Animations.Animation#load
601+
* @private
600602
* @since 3.0.0
601603
*
602604
* @param {Phaser.GameObjects.Components.Animation} component - [description]
@@ -613,11 +615,12 @@ var Animation = new Class({
613615
{
614616
component.currentAnim = this;
615617

616-
component._timeScale = 1;
617618
component.frameRate = this.frameRate;
618619
component.duration = this.duration;
619620
component.msPerFrame = this.msPerFrame;
620621
component.skipMissedFrames = this.skipMissedFrames;
622+
623+
component._timeScale = 1;
621624
component._delay = this.delay;
622625
component._repeat = this.repeat;
623626
component._repeatDelay = this.repeatDelay;
@@ -648,7 +651,7 @@ var Animation = new Class({
648651
// We're at the end of the animation
649652

650653
// Yoyo? (happens before repeat)
651-
if (this.yoyo)
654+
if (component.yoyo)
652655
{
653656
component.forward = false;
654657

@@ -766,7 +769,7 @@ var Animation = new Class({
766769
{
767770
component.pendingRepeat = true;
768771
component.accumulator -= component.nextTick;
769-
component.nextTick += (component._repeatDelay * 1000);
772+
component.nextTick += component._repeatDelay;
770773
}
771774
else
772775
{

src/animations/AnimationManager.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,24 +511,28 @@ var AnimationManager = new Class({
511511
},
512512

513513
/**
514-
* [description]
514+
* Takes an array of Game Objects that have the Animation Component and then
515+
* starts the given animation playing on them, each one offset by the
516+
* `stagger` amount given to this method.
515517
*
516518
* @method Phaser.Animations.AnimationManager#staggerPlay
517519
* @since 3.0.0
520+
*
521+
* @generic {Phaser.GameObjects.GameObject[]} G - [items,$return]
518522
*
519-
* @param {string} key - [description]
520-
* @param {Phaser.GameObjects.GameObject} child - [description]
521-
* @param {number} [stagger=0] - [description]
523+
* @param {string} key - The key of the animation to play on the Game Objects.
524+
* @param {Phaser.GameObjects.GameObject[]} children - An array of Game Objects to play the animation on. They must have the Animation Component.
525+
* @param {number} [stagger=0] - The amount of time, in milliseconds, to offset each play time by.
522526
*
523527
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
524528
*/
525-
staggerPlay: function (key, child, stagger)
529+
staggerPlay: function (key, children, stagger)
526530
{
527531
if (stagger === undefined) { stagger = 0; }
528532

529-
if (!Array.isArray(child))
533+
if (!Array.isArray(children))
530534
{
531-
child = [ child ];
535+
children = [ children ];
532536
}
533537

534538
var anim = this.get(key);
@@ -538,9 +542,9 @@ var AnimationManager = new Class({
538542
return;
539543
}
540544

541-
for (var i = 0; i < child.length; i++)
545+
for (var i = 0; i < children.length; i++)
542546
{
543-
child[i].anims.delayedPlay(stagger * i, key);
547+
children[i].anims.delayedPlay(stagger * i, key);
544548
}
545549

546550
return this;

0 commit comments

Comments
 (0)