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 #3963

This commit is contained in:
Richard Davey 2020-09-01 17:00:16 +01:00
parent 8d02da00f2
commit 18cdb5e618

View file

@ -522,13 +522,15 @@ var Animation = new Class({
* @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.
* @param {boolean} [ignoreIfPlaying=false] - If this animation is already playing then ignore this call.
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
* @param {number} [timeScale] - Set the Time Scale when starting this Animation. If not given, the Time Scale will use the current value.
*
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
*/
play: function (key, ignoreIfPlaying, startFrame)
play: function (key, ignoreIfPlaying, startFrame, timeScale)
{
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
if (startFrame === undefined) { startFrame = 0; }
if (timeScale === undefined) { timeScale = this._timeScale; }
if (key instanceof BaseAnimation)
{
@ -544,6 +546,7 @@ var Animation = new Class({
this._reverse = false;
this._paused = false;
this._wasPlaying = true;
this._timeScale = timeScale;
return this._startAnimation(key, startFrame);
},
@ -558,13 +561,15 @@ var Animation = new Class({
* @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.
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
* @param {number} [timeScale] - Set the Time Scale when starting this Animation. If not given, the Time Scale will use the current value.
*
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
*/
playReverse: function (key, ignoreIfPlaying, startFrame)
playReverse: function (key, ignoreIfPlaying, startFrame, timeScale)
{
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
if (startFrame === undefined) { startFrame = 0; }
if (timeScale === undefined) { timeScale = this._timeScale; }
if (key instanceof BaseAnimation)
{
@ -578,6 +583,7 @@ var Animation = new Class({
this.forward = false;
this._reverse = true;
this._timeScale = timeScale;
return this._startAnimation(key, startFrame);
},
@ -930,9 +936,11 @@ var Animation = new Class({
},
/**
* Sets the Time Scale factor, allowing you to make the animation go go faster or slower than default.
* Sets the Time Scale factor, allowing you to make the animation go faster or slower than default.
* Where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
*
* Setting the time scale impacts all animations played on this Sprite from this point on.
*
* @method Phaser.GameObjects.Components.Animation#setTimeScale
* @since 3.4.0
*