Skip to content

Commit 18cdb5e

Browse files
committed
The Animation.play and playReverse methods have a new optional parameter timeScale. This allows you to set the Animations time scale as you're actually playing it, rather than having to chain two calls together. Close phaserjs#3963
1 parent 8d02da0 commit 18cdb5e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/gameobjects/components/Animation.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,15 @@ var Animation = new Class({
522522
* @param {(string|Phaser.Animations.Animation)} key - The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance.
523523
* @param {boolean} [ignoreIfPlaying=false] - If this animation is already playing then ignore this call.
524524
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
525+
* @param {number} [timeScale] - Set the Time Scale when starting this Animation. If not given, the Time Scale will use the current value.
525526
*
526527
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
527528
*/
528-
play: function (key, ignoreIfPlaying, startFrame)
529+
play: function (key, ignoreIfPlaying, startFrame, timeScale)
529530
{
530531
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
531532
if (startFrame === undefined) { startFrame = 0; }
533+
if (timeScale === undefined) { timeScale = this._timeScale; }
532534

533535
if (key instanceof BaseAnimation)
534536
{
@@ -544,6 +546,7 @@ var Animation = new Class({
544546
this._reverse = false;
545547
this._paused = false;
546548
this._wasPlaying = true;
549+
this._timeScale = timeScale;
547550

548551
return this._startAnimation(key, startFrame);
549552
},
@@ -558,13 +561,15 @@ var Animation = new Class({
558561
* @param {(string|Phaser.Animations.Animation)} key - The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance.
559562
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
560563
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
564+
* @param {number} [timeScale] - Set the Time Scale when starting this Animation. If not given, the Time Scale will use the current value.
561565
*
562566
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
563567
*/
564-
playReverse: function (key, ignoreIfPlaying, startFrame)
568+
playReverse: function (key, ignoreIfPlaying, startFrame, timeScale)
565569
{
566570
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
567571
if (startFrame === undefined) { startFrame = 0; }
572+
if (timeScale === undefined) { timeScale = this._timeScale; }
568573

569574
if (key instanceof BaseAnimation)
570575
{
@@ -578,6 +583,7 @@ var Animation = new Class({
578583

579584
this.forward = false;
580585
this._reverse = true;
586+
this._timeScale = timeScale;
581587

582588
return this._startAnimation(key, startFrame);
583589
},
@@ -930,9 +936,11 @@ var Animation = new Class({
930936
},
931937

932938
/**
933-
* Sets the Time Scale factor, allowing you to make the animation go go faster or slower than default.
939+
* Sets the Time Scale factor, allowing you to make the animation go faster or slower than default.
934940
* Where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
935941
*
942+
* Setting the time scale impacts all animations played on this Sprite from this point on.
943+
*
936944
* @method Phaser.GameObjects.Components.Animation#setTimeScale
937945
* @since 3.4.0
938946
*

0 commit comments

Comments
 (0)