Skip to content

Commit 96bc2e8

Browse files
committed
Removed load and fixed staggerPlay
1 parent b4b5338 commit 96bc2e8

1 file changed

Lines changed: 82 additions & 91 deletions

File tree

src/animations/AnimationManager.js

Lines changed: 82 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ var AnimationManager = new Class({
153153

154154
/**
155155
* Checks to see if the given key is already in use within the Animation Manager or not.
156-
*
156+
*
157157
* Animations are global. Keys created in one scene can be used from any other Scene in your game. They are not Scene specific.
158158
*
159159
* @method Phaser.Animations.AnimationManager#exists
@@ -170,15 +170,15 @@ var AnimationManager = new Class({
170170

171171
/**
172172
* Creates a new Animation and adds it to the Animation Manager.
173-
*
173+
*
174174
* Animations are global. Once created, you can use them in any Scene in your game. They are not Scene specific.
175-
*
175+
*
176176
* If an invalid key is given this method will return `false`.
177-
*
177+
*
178178
* If you pass the key of an animation that already exists in the Animation Manager, that animation will be returned.
179-
*
179+
*
180180
* A brand new animation is only created if the key is valid and not already in use.
181-
*
181+
*
182182
* If you wish to re-use an existing key, call `AnimationManager.remove` first, then this method.
183183
*
184184
* @method Phaser.Animations.AnimationManager#create
@@ -204,7 +204,7 @@ var AnimationManager = new Class({
204204
anim = new Animation(this, key, config);
205205

206206
this.anims.set(key, anim);
207-
207+
208208
this.emit(Events.ADD_ANIMATION, key, anim);
209209
}
210210
}
@@ -265,18 +265,18 @@ var AnimationManager = new Class({
265265
* Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object.
266266
*
267267
* Generates objects with string based frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNames}.
268-
*
268+
*
269269
* It's a helper method, designed to make it easier for you to extract all of the frame names from texture atlases.
270270
* If you're working with a sprite sheet, see the `generateFrameNumbers` method instead.
271-
*
271+
*
272272
* Example:
273-
*
273+
*
274274
* If you have a texture atlases loaded called `gems` and it contains 6 frames called `ruby_0001`, `ruby_0002`, and so on,
275275
* then you can call this method using: `this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 })`.
276-
*
276+
*
277277
* The `end` value tells it to look for 6 frames, incrementally numbered, all starting with the prefix `ruby_`. The `zeroPad`
278278
* value tells it how many zeroes pad out the numbers. To create an animation using this method, you can do:
279-
*
279+
*
280280
* ```javascript
281281
* this.anims.create({
282282
* key: 'ruby',
@@ -288,7 +288,7 @@ var AnimationManager = new Class({
288288
* })
289289
* });
290290
* ```
291-
*
291+
*
292292
* Please see the animation examples for further details.
293293
*
294294
* @method Phaser.Animations.AnimationManager#generateFrameNames
@@ -367,7 +367,7 @@ var AnimationManager = new Class({
367367
* Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object.
368368
*
369369
* Generates objects with numbered frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNumbers}.
370-
*
370+
*
371371
* If you're working with a texture atlas, see the `generateFrameNames` method instead.
372372
*
373373
* @method Phaser.Animations.AnimationManager#generateFrameNumbers
@@ -452,90 +452,121 @@ var AnimationManager = new Class({
452452
},
453453

454454
/**
455-
* Load an Animation into a Game Object's Animation Component.
455+
* Pause all animations.
456456
*
457-
* @method Phaser.Animations.AnimationManager#load
457+
* @method Phaser.Animations.AnimationManager#pauseAll
458+
* @fires Phaser.Animations.Events#PAUSE_ALL
458459
* @since 3.0.0
459460
*
460-
* @param {Phaser.GameObjects.GameObject} child - The Game Object to load the animation into.
461-
* @param {string} key - The key of the animation to load.
462-
* @param {(string|integer)} [startFrame] - The name of a start frame to set on the loaded animation.
463-
*
464-
* @return {Phaser.GameObjects.GameObject} The Game Object with the animation loaded into it.
461+
* @return {this} This Animation Manager.
465462
*/
466-
load: function (child, key, startFrame)
463+
pauseAll: function ()
467464
{
468-
var anim = this.get(key);
469-
470-
if (anim)
471-
{
472-
anim.load(child, startFrame);
473-
}
474-
else
465+
if (!this.paused)
475466
{
476-
console.warn('Missing animation: ' + key);
467+
this.paused = true;
468+
469+
this.emit(Events.PAUSE_ALL);
477470
}
478471

479-
return child;
472+
return this;
480473
},
481474

482475
/**
483-
* Pause all animations.
476+
* Play an animation on the given Game Objects that have an Animation Component.
484477
*
485-
* @method Phaser.Animations.AnimationManager#pauseAll
486-
* @fires Phaser.Animations.Events#PAUSE_ALL
478+
* @method Phaser.Animations.AnimationManager#play
487479
* @since 3.0.0
488480
*
481+
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
482+
* @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} children - An array of Game Objects to play the animation on. They must have an Animation Component.
483+
*
489484
* @return {this} This Animation Manager.
490485
*/
491-
pauseAll: function ()
486+
play: function (key, children)
492487
{
493-
if (!this.paused)
488+
if (!Array.isArray(children))
494489
{
495-
this.paused = true;
490+
children = [ children ];
491+
}
496492

497-
this.emit(Events.PAUSE_ALL);
493+
for (var i = 0; i < children.length; i++)
494+
{
495+
children[i].anims.play(key);
498496
}
499497

500498
return this;
501499
},
502500

503501
/**
504-
* Play an animation on the given Game Objects that have an Animation Component.
502+
* Takes an array of Game Objects that have an Animation Component and then
503+
* starts the given animation playing on them. The start time of each Game Object
504+
* is offset, incrementally, by the `stagger` amount.
505505
*
506-
* @method Phaser.Animations.AnimationManager#play
506+
* For example, if you pass an array with 4 children and a stagger time of 1000,
507+
* the delays will be:
508+
*
509+
* child 1: 1000ms delay
510+
* child 2: 2000ms delay
511+
* child 3: 3000ms delay
512+
* child 4: 4000ms delay
513+
*
514+
* If you set the `staggerFirst` parameter to `false` they would be:
515+
*
516+
* child 1: 0ms delay
517+
* child 2: 1000ms delay
518+
* child 3: 2000ms delay
519+
* child 4: 3000ms delay
520+
*
521+
* You can also set `stagger` to be a negative value. If it was -1000, the above would be:
522+
*
523+
* child 1: 3000ms delay
524+
* child 2: 2000ms delay
525+
* child 3: 1000ms delay
526+
* child 4: 0ms delay
527+
*
528+
* @method Phaser.Animations.AnimationManager#staggerPlay
507529
* @since 3.0.0
508530
*
509-
* @param {string} key - The key of the animation to play on the Game Object.
510-
* @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} child - The Game Objects to play the animation on.
531+
* @generic {Phaser.GameObjects.GameObject[]} G - [items,$return]
532+
*
533+
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
534+
* @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} children - An array of Game Objects to play the animation on. They must have an Animation Component.
535+
* @param {number} stagger - The amount of time, in milliseconds, to offset each play time by. If a negative value is given, it's applied to the children in reverse order.
536+
* @param {boolean} [staggerFirst=true] -Should the first child be staggered as well?
511537
*
512538
* @return {this} This Animation Manager.
513539
*/
514-
play: function (key, child)
540+
staggerPlay: function (key, children, stagger, staggerFirst)
515541
{
516-
if (!Array.isArray(child))
542+
if (stagger === undefined) { stagger = 0; }
543+
if (staggerFirst === undefined) { staggerFirst = true; }
544+
545+
if (!Array.isArray(children))
517546
{
518-
child = [ child ];
547+
children = [ children ];
519548
}
520549

521-
var anim = this.get(key);
550+
var len = children.length;
522551

523-
if (!anim)
552+
if (!staggerFirst)
524553
{
525-
return this;
554+
len--;
526555
}
527556

528-
for (var i = 0; i < child.length; i++)
557+
for (var i = 0; i < children.length; i++)
529558
{
530-
child[i].anims.play(key);
559+
var time = (stagger < 0) ? Math.abs(stagger) * (len - i) : stagger * i;
560+
561+
children[i].anims.delayedPlay(time, key);
531562
}
532563

533564
return this;
534565
},
535566

536567
/**
537568
* Removes an Animation from this Animation Manager, based on the given key.
538-
*
569+
*
539570
* This is a global action. Once an Animation has been removed, no Game Objects
540571
* can carry on using it.
541572
*
@@ -582,46 +613,6 @@ var AnimationManager = new Class({
582613
return this;
583614
},
584615

585-
/**
586-
* Takes an array of Game Objects that have an Animation Component and then
587-
* starts the given animation playing on them, each one offset by the
588-
* `stagger` amount given to this method.
589-
*
590-
* @method Phaser.Animations.AnimationManager#staggerPlay
591-
* @since 3.0.0
592-
*
593-
* @generic {Phaser.GameObjects.GameObject[]} G - [items,$return]
594-
*
595-
* @param {string} key - The key of the animation to play on the Game Objects.
596-
* @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} children - An array of Game Objects to play the animation on. They must have an Animation Component.
597-
* @param {number} [stagger=0] - The amount of time, in milliseconds, to offset each play time by.
598-
*
599-
* @return {this} This Animation Manager.
600-
*/
601-
staggerPlay: function (key, children, stagger)
602-
{
603-
if (stagger === undefined) { stagger = 0; }
604-
605-
if (!Array.isArray(children))
606-
{
607-
children = [ children ];
608-
}
609-
610-
var anim = this.get(key);
611-
612-
if (!anim)
613-
{
614-
return this;
615-
}
616-
617-
for (var i = 0; i < children.length; i++)
618-
{
619-
children[i].anims.delayedPlay(stagger * i, key);
620-
}
621-
622-
return this;
623-
},
624-
625616
/**
626617
* Returns the Animation data as JavaScript object based on the given key.
627618
* Or, if not key is defined, it will return the data of all animations as array of objects.

0 commit comments

Comments
 (0)