2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2013-08-28 23:09:12 +00:00
|
|
|
/**
|
2014-11-20 05:26:43 +00:00
|
|
|
* A Tween allows you to alter one or more properties of a target object over a defined period of time.
|
|
|
|
* This can be used for things such as alpha fading Sprites, scaling them or motion.
|
|
|
|
* Use `Tween.to` or `Tween.from` to set-up the tween values. You can create multiple tweens on the same object
|
|
|
|
* by calling Tween.to multiple times on the same Tween. Additional tweens specified in this way become "child" tweens and
|
|
|
|
* are played through in sequence. You can use Tween.timeScale and Tween.reverse to control the playback of this Tween and all of its children.
|
2013-08-28 23:09:12 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.Tween
|
|
|
|
* @constructor
|
2014-11-20 05:26:43 +00:00
|
|
|
* @param {object} target - The target object, such as a Phaser.Sprite or Phaser.Sprite.scale.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {Phaser.Game} game - Current game instance.
|
2014-03-07 01:26:09 +00:00
|
|
|
* @param {Phaser.TweenManager} manager - The TweenManager responsible for looking after this Tween.
|
2013-08-28 23:09:12 +00:00
|
|
|
*/
|
2014-11-18 20:58:25 +00:00
|
|
|
Phaser.Tween = function (target, game, manager) {
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
|
|
|
*/
|
2013-08-28 23:09:12 +00:00
|
|
|
this.game = game;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-19 21:11:07 +00:00
|
|
|
* @property {object} target - The target object, such as a Phaser.Sprite or property like Phaser.Sprite.scale.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-18 20:58:25 +00:00
|
|
|
this.target = target;
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-19 21:11:07 +00:00
|
|
|
* @property {Phaser.TweenManager} manager - Reference to the TweenManager responsible for updating this Tween.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-18 20:58:25 +00:00
|
|
|
this.manager = manager;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-19 21:11:07 +00:00
|
|
|
* @property {Array} timeline - An Array of TweenData objects that comprise the different parts of this Tween.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-19 21:11:07 +00:00
|
|
|
this.timeline = [];
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* If set to `true` the current tween will play in reverse.
|
|
|
|
* If the tween hasn't yet started this has no effect.
|
|
|
|
* If there are child tweens then all child tweens will play in reverse from the current point.
|
|
|
|
* @property {boolean} reverse
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2014-11-19 21:11:07 +00:00
|
|
|
this.reverse = false;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* The speed at which the tweens will run. A value of 1 means it will match the game frame rate. 0.5 will run at half the frame rate. 2 at double the frame rate, etc.
|
|
|
|
* If a tweens duration is 1 second but timeScale is 0.5 then it will take 2 seconds to complete.
|
2015-05-09 00:42:29 +00:00
|
|
|
*
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {number} timeScale
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.timeScale = 1;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-19 21:11:07 +00:00
|
|
|
* @property {number} repeatCounter - If the Tween and any child tweens are set to repeat this contains the current repeat count.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-19 21:11:07 +00:00
|
|
|
this.repeatCounter = 0;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {boolean} pendingDelete - True if this Tween is ready to be deleted by the TweenManager.
|
|
|
|
* @default
|
2014-11-30 11:10:52 +00:00
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.pendingDelete = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-02-05 02:39:03 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* The onStart event is fired when the Tween begins. If there is a delay before the tween starts then onStart fires after the delay is finished.
|
|
|
|
* It will be sent 2 parameters: the target object and this tween.
|
|
|
|
* @property {Phaser.Signal} onStart
|
2014-02-05 02:39:03 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.onStart = new Phaser.Signal();
|
2014-02-05 02:39:03 +00:00
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
/**
|
2016-04-05 00:06:05 +00:00
|
|
|
* The onLoop event is fired if the Tween, or any child tweens loop.
|
2014-11-20 00:21:14 +00:00
|
|
|
* It will be sent 2 parameters: the target object and this tween.
|
2016-04-05 00:06:05 +00:00
|
|
|
*
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {Phaser.Signal} onLoop
|
2014-02-26 23:27:22 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.onLoop = new Phaser.Signal();
|
2014-02-26 23:27:22 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-20 02:17:41 +00:00
|
|
|
* The onRepeat event is fired if the Tween and all of its children repeats. If this tween has no children this will never be fired.
|
|
|
|
* It will be sent 2 parameters: the target object and this tween.
|
|
|
|
* @property {Phaser.Signal} onRepeat
|
|
|
|
*/
|
|
|
|
this.onRepeat = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The onChildComplete event is fired when the Tween or any of its children completes.
|
|
|
|
* Fires every time a child completes unless a child is set to repeat forever.
|
|
|
|
* It will be sent 2 parameters: the target object and this tween.
|
|
|
|
* @property {Phaser.Signal} onChildComplete
|
|
|
|
*/
|
|
|
|
this.onChildComplete = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The onComplete event is fired when the Tween and all of its children completes. Does not fire if the Tween is set to loop or repeatAll(-1).
|
2014-11-20 00:21:14 +00:00
|
|
|
* It will be sent 2 parameters: the target object and this tween.
|
|
|
|
* @property {Phaser.Signal} onComplete
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.onComplete = new Phaser.Signal();
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {boolean} isRunning - If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state or waiting to start are considered as being running.
|
|
|
|
* @default
|
2014-02-26 23:27:22 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.isRunning = false;
|
2014-02-26 23:27:22 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {number} current - The current Tween child being run.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2014-11-30 11:10:52 +00:00
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this.current = 0;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
/**
|
2014-11-30 11:10:52 +00:00
|
|
|
* @property {object} properties - Target property cache used when building the child data values.
|
2014-11-20 05:26:43 +00:00
|
|
|
*/
|
|
|
|
this.properties = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Tween} chainedTween - If this Tween is chained to another this holds a reference to it.
|
|
|
|
*/
|
|
|
|
this.chainedTween = null;
|
|
|
|
|
Tweens have been completely rewritten. They're now much more flexible and efficient than before:
When specifying the ease in `Tween.to` or `Tween.from` you can now use a string instead of the Function. This makes your code less verbose. For example instead of `Phaser.Easing.Sinusoidal.Out` and you can now just use the string "Sine".The string names match those used by TweenMax and includes: "Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce", "Power0", "Power1", "Power2", "Power3" and "Power4". You can append ".easeIn", ".easeOut" and "easeInOut" variants. All are supported for each ease types.
Tweens now create a TweenData object. The Tween object itself acts like more of a timeline, managing multiple TweenData objects. You can now call `Tween.to` and each call will create a new child tween that is added to the timeline, which are played through in sequence.
Tweens are now bound to the new Time.desiredFps value and update based on the new Game core loop, rather than being bound to time calculations. This means that tweens are now running with the same update logic as physics and the core loop.
Tween.timeScale allows you to scale the duration of a tween (and any child tweens it may have). A value of 1.0 means it should play at the desiredFps rate. A value of 0.5 will run at half the frame rate, 2 at double and so on. You can even tween the timeScale value for interesting effects!
Tween.reverse allows you to instantly reverse an active tween. If the Tween has children then it will smoothly reverse through all child tweens as well.
Tween.repeatAll allows you to control how many times all child tweens will repeat before firing the Tween.onComplete event. You can set the value to -1 to repeat forever.
Tween.loop now controls the looping of all child tweens.
Tween.onRepeat is a new signal that is dispatched whenever a Tween repeats. If a Tween has many child tweens its dispatched once the sequence has repeated.
Tween.onChildComplete is a new signal that is dispatched whenever any child tweens have completed. If a Tween consists of 4 sections you will get 3 onChildComplete events followed by 1 onComplete event as the final tween finishes.
Chained tweens are now more intelligently handled. Because you can easily create child tweens (by simply calling Tween.to multiple times) chained tweens are now used to kick-off longer sequences. You can pass as many Tween objects to `Tween.chain` as you like as they'll all be played in sequence. As one Tween completes it passes on to the next until the entire chain is finished.
Tween.stop has a new `complete` parameter that if set will still fire the onComplete event and start the next chained tween, if there is one.
Tween.delay, Tween.repeat, Tween.yoyo, Tween.easing and Tween.interpolation all have a new `index` parameter. This allows you to target specific child tweens, or if set to -1 it will update all children at once.
Tween.totalDuration reports the total duration of all child tweens in ms.
There are new easing aliases:
* Phaser.Easing.Power0 = Phaser.Easing.Linear.None
* Phaser.Easing.Power1 = Phaser.Easing.Quadratic.Out
* Phaser.Easing.Power2 = Phaser.Easing.Cubic.Out
* Phaser.Easing.Power3 = Phaser.Easing.Quartic.Out
* Phaser.Easing.Power4 = Phaser.Easing.Quintic.Out
2014-11-20 06:04:54 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} isPaused - Is this Tween paused or not?
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.isPaused = false;
|
|
|
|
|
2015-07-30 14:27:51 +00:00
|
|
|
/**
|
|
|
|
* Is this Tween frame or time based? A frame based tween will use the physics elapsed timer when updating. This means
|
|
|
|
* it will retain the same consistent frame rate, regardless of the speed of the device. The duration value given should
|
|
|
|
* be given in frames.
|
2015-11-11 17:39:05 +00:00
|
|
|
*
|
2015-07-30 14:27:51 +00:00
|
|
|
* If the Tween uses a time based update (which is the default) then the duration is given in milliseconds.
|
|
|
|
* In this situation a 2000ms tween will last exactly 2 seconds, regardless of the device and how many visual updates the tween
|
|
|
|
* has actually been through. For very short tweens you may wish to experiment with a frame based update instead.
|
2015-08-20 11:59:06 +00:00
|
|
|
*
|
|
|
|
* The default value is whatever you've set in TweenManager.frameBased.
|
2015-11-11 17:39:05 +00:00
|
|
|
*
|
2015-07-30 14:27:51 +00:00
|
|
|
* @property {boolean} frameBased
|
|
|
|
* @default
|
|
|
|
*/
|
2015-08-20 11:59:06 +00:00
|
|
|
this.frameBased = manager.frameBased;
|
2015-07-30 14:27:51 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {function} _onUpdateCallback - An onUpdate callback.
|
|
|
|
* @private
|
|
|
|
* @default null
|
2014-11-19 21:11:07 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this._onUpdateCallback = null;
|
2014-11-19 21:11:07 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {object} _onUpdateCallbackContext - The context in which to call the onUpdate callback.
|
|
|
|
* @private
|
|
|
|
* @default null
|
2013-12-18 13:01:45 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this._onUpdateCallbackContext = null;
|
2013-12-18 13:01:45 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {number} _pausedTime - Private pause timer.
|
|
|
|
* @private
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this._pausedTime = 0;
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-19 21:11:07 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* @property {boolean} _codePaused - Was the Tween paused by code or by Game focus loss?
|
|
|
|
* @private
|
2014-11-19 21:11:07 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
this._codePaused = false;
|
2014-11-18 20:58:25 +00:00
|
|
|
|
2015-04-27 13:00:11 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} _hasStarted - Internal var to track if the Tween has started yet or not.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._hasStarted = false;
|
2013-08-28 23:09:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Tween.prototype = {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2014-07-07 10:07:00 +00:00
|
|
|
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
|
|
|
|
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
|
2014-11-19 21:11:07 +00:00
|
|
|
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
|
|
|
|
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#to
|
2015-02-16 12:23:54 +00:00
|
|
|
* @param {object} properties - An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
|
2015-07-30 14:27:51 +00:00
|
|
|
* @param {number} [duration=1000] - Duration of this tween in ms. Or if `Tween.frameBased` is true this represents the number of frames that should elapse.
|
2014-11-19 21:11:07 +00:00
|
|
|
* @param {function|string} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden.
|
|
|
|
* @param {boolean} [autoStart=false] - Set to `true` to allow this tween to start automatically. Otherwise call Tween.start().
|
|
|
|
* @param {number} [delay=0] - Delay before this tween will start in milliseconds. Defaults to 0, no delay.
|
2016-02-17 02:57:45 +00:00
|
|
|
* @param {number} [repeat=0] - Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens.
|
2014-04-08 23:59:53 +00:00
|
|
|
* @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
|
2013-12-18 13:01:45 +00:00
|
|
|
* @return {Phaser.Tween} This Tween object.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-12-30 16:54:00 +00:00
|
|
|
to: function (properties, duration, ease, autoStart, delay, repeat, yoyo) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (duration === undefined || duration <= 0) { duration = 1000; }
|
|
|
|
if (ease === undefined || ease === null) { ease = Phaser.Easing.Default; }
|
|
|
|
if (autoStart === undefined) { autoStart = false; }
|
|
|
|
if (delay === undefined) { delay = 0; }
|
|
|
|
if (repeat === undefined) { repeat = 0; }
|
|
|
|
if (yoyo === undefined) { yoyo = false; }
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2014-11-19 21:11:07 +00:00
|
|
|
if (typeof ease === 'string' && this.manager.easeMap[ease])
|
2014-04-22 01:12:21 +00:00
|
|
|
{
|
2014-11-19 21:11:07 +00:00
|
|
|
ease = this.manager.easeMap[ease];
|
2014-04-22 01:12:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
if (this.isRunning)
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Tween.to cannot be called after Tween.start');
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.timeline.push(new Phaser.TweenData(this).to(properties, duration, ease, delay, repeat, yoyo));
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
if (autoStart)
|
|
|
|
{
|
2014-11-19 21:11:07 +00:00
|
|
|
this.start();
|
2013-08-28 23:09:12 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 21:11:07 +00:00
|
|
|
return this;
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
},
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-05-01 15:34:14 +00:00
|
|
|
/**
|
2014-11-20 05:26:43 +00:00
|
|
|
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
|
|
|
|
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
|
2014-11-19 21:11:07 +00:00
|
|
|
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
|
|
|
|
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
|
2014-05-01 15:34:14 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#from
|
2014-11-19 21:11:07 +00:00
|
|
|
* @param {object} properties - An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
|
2015-07-30 14:27:51 +00:00
|
|
|
* @param {number} [duration=1000] - Duration of this tween in ms. Or if `Tween.frameBased` is true this represents the number of frames that should elapse.
|
2014-11-19 21:11:07 +00:00
|
|
|
* @param {function|string} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden.
|
|
|
|
* @param {boolean} [autoStart=false] - Set to `true` to allow this tween to start automatically. Otherwise call Tween.start().
|
|
|
|
* @param {number} [delay=0] - Delay before this tween will start in milliseconds. Defaults to 0, no delay.
|
2016-02-17 02:57:45 +00:00
|
|
|
* @param {number} [repeat=0] - Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens.
|
2014-05-01 15:34:14 +00:00
|
|
|
* @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
|
|
|
|
* @return {Phaser.Tween} This Tween object.
|
|
|
|
*/
|
Tweens have been completely rewritten. They're now much more flexible and efficient than before:
When specifying the ease in `Tween.to` or `Tween.from` you can now use a string instead of the Function. This makes your code less verbose. For example instead of `Phaser.Easing.Sinusoidal.Out` and you can now just use the string "Sine".The string names match those used by TweenMax and includes: "Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce", "Power0", "Power1", "Power2", "Power3" and "Power4". You can append ".easeIn", ".easeOut" and "easeInOut" variants. All are supported for each ease types.
Tweens now create a TweenData object. The Tween object itself acts like more of a timeline, managing multiple TweenData objects. You can now call `Tween.to` and each call will create a new child tween that is added to the timeline, which are played through in sequence.
Tweens are now bound to the new Time.desiredFps value and update based on the new Game core loop, rather than being bound to time calculations. This means that tweens are now running with the same update logic as physics and the core loop.
Tween.timeScale allows you to scale the duration of a tween (and any child tweens it may have). A value of 1.0 means it should play at the desiredFps rate. A value of 0.5 will run at half the frame rate, 2 at double and so on. You can even tween the timeScale value for interesting effects!
Tween.reverse allows you to instantly reverse an active tween. If the Tween has children then it will smoothly reverse through all child tweens as well.
Tween.repeatAll allows you to control how many times all child tweens will repeat before firing the Tween.onComplete event. You can set the value to -1 to repeat forever.
Tween.loop now controls the looping of all child tweens.
Tween.onRepeat is a new signal that is dispatched whenever a Tween repeats. If a Tween has many child tweens its dispatched once the sequence has repeated.
Tween.onChildComplete is a new signal that is dispatched whenever any child tweens have completed. If a Tween consists of 4 sections you will get 3 onChildComplete events followed by 1 onComplete event as the final tween finishes.
Chained tweens are now more intelligently handled. Because you can easily create child tweens (by simply calling Tween.to multiple times) chained tweens are now used to kick-off longer sequences. You can pass as many Tween objects to `Tween.chain` as you like as they'll all be played in sequence. As one Tween completes it passes on to the next until the entire chain is finished.
Tween.stop has a new `complete` parameter that if set will still fire the onComplete event and start the next chained tween, if there is one.
Tween.delay, Tween.repeat, Tween.yoyo, Tween.easing and Tween.interpolation all have a new `index` parameter. This allows you to target specific child tweens, or if set to -1 it will update all children at once.
Tween.totalDuration reports the total duration of all child tweens in ms.
There are new easing aliases:
* Phaser.Easing.Power0 = Phaser.Easing.Linear.None
* Phaser.Easing.Power1 = Phaser.Easing.Quadratic.Out
* Phaser.Easing.Power2 = Phaser.Easing.Cubic.Out
* Phaser.Easing.Power3 = Phaser.Easing.Quartic.Out
* Phaser.Easing.Power4 = Phaser.Easing.Quintic.Out
2014-11-20 06:04:54 +00:00
|
|
|
from: function (properties, duration, ease, autoStart, delay, repeat, yoyo) {
|
2014-07-07 10:07:00 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (duration === undefined) { duration = 1000; }
|
|
|
|
if (ease === undefined || ease === null) { ease = Phaser.Easing.Default; }
|
|
|
|
if (autoStart === undefined) { autoStart = false; }
|
|
|
|
if (delay === undefined) { delay = 0; }
|
|
|
|
if (repeat === undefined) { repeat = 0; }
|
|
|
|
if (yoyo === undefined) { yoyo = false; }
|
2014-07-07 10:07:00 +00:00
|
|
|
|
2014-11-19 21:11:07 +00:00
|
|
|
if (typeof ease === 'string' && this.manager.easeMap[ease])
|
2014-07-07 10:07:00 +00:00
|
|
|
{
|
2014-11-19 21:11:07 +00:00
|
|
|
ease = this.manager.easeMap[ease];
|
2014-05-01 15:34:14 +00:00
|
|
|
}
|
2014-07-07 10:07:00 +00:00
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
if (this.isRunning)
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Tween.from cannot be called after Tween.start');
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.timeline.push(new Phaser.TweenData(this).from(properties, duration, ease, delay, repeat, yoyo));
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
if (autoStart)
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-19 21:11:07 +00:00
|
|
|
this.start();
|
2013-11-25 04:40:04 +00:00
|
|
|
}
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-19 21:11:07 +00:00
|
|
|
return this;
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
},
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-03-03 22:43:35 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* Starts the tween running. Can also be called by the autoStart parameter of `Tween.to` or `Tween.from`.
|
|
|
|
* This sets the `Tween.isRunning` property to `true` and dispatches a `Tween.onStart` signal.
|
|
|
|
* If the Tween has a delay set then nothing will start tweening until the delay has expired.
|
2014-03-03 22:43:35 +00:00
|
|
|
*
|
2014-11-18 20:58:25 +00:00
|
|
|
* @method Phaser.Tween#start
|
2014-11-19 21:11:07 +00:00
|
|
|
* @param {number} [index=0] - If this Tween contains child tweens you can specify which one to start from. The default is zero, i.e. the first tween created.
|
2014-11-18 20:58:25 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2014-03-03 22:43:35 +00:00
|
|
|
*/
|
2014-11-18 20:58:25 +00:00
|
|
|
start: function (index) {
|
2014-03-03 22:43:35 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (index === undefined) { index = 0; }
|
2014-11-20 00:21:14 +00:00
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
if (this.game === null || this.target === null || this.timeline.length === 0 || this.isRunning)
|
2014-03-03 22:43:35 +00:00
|
|
|
{
|
2014-11-18 20:58:25 +00:00
|
|
|
return this;
|
2014-03-03 22:43:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
// Populate the tween data
|
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
|
|
|
{
|
|
|
|
// Build our master property list with the starting values
|
|
|
|
for (var property in this.timeline[i].vEnd)
|
|
|
|
{
|
|
|
|
this.properties[property] = this.target[property] || 0;
|
|
|
|
|
|
|
|
if (!Array.isArray(this.properties[property]))
|
|
|
|
{
|
|
|
|
// Ensures we're using numbers, not strings
|
|
|
|
this.properties[property] *= 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
|
|
|
{
|
|
|
|
this.timeline[i].loadValues();
|
|
|
|
}
|
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
this.manager.add(this);
|
2014-03-03 22:43:35 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
this.isRunning = true;
|
2014-03-03 22:43:35 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
if (index < 0 || index > this.timeline.length - 1)
|
2014-09-02 14:45:52 +00:00
|
|
|
{
|
2014-11-18 20:58:25 +00:00
|
|
|
index = 0;
|
2014-09-02 14:45:52 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
this.current = index;
|
2014-09-02 14:45:52 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
this.timeline[this.current].start();
|
2014-03-04 01:27:57 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
return this;
|
2014-03-03 22:43:35 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* Stops the tween if running and flags it for deletion from the TweenManager.
|
Tweens have been completely rewritten. They're now much more flexible and efficient than before:
When specifying the ease in `Tween.to` or `Tween.from` you can now use a string instead of the Function. This makes your code less verbose. For example instead of `Phaser.Easing.Sinusoidal.Out` and you can now just use the string "Sine".The string names match those used by TweenMax and includes: "Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce", "Power0", "Power1", "Power2", "Power3" and "Power4". You can append ".easeIn", ".easeOut" and "easeInOut" variants. All are supported for each ease types.
Tweens now create a TweenData object. The Tween object itself acts like more of a timeline, managing multiple TweenData objects. You can now call `Tween.to` and each call will create a new child tween that is added to the timeline, which are played through in sequence.
Tweens are now bound to the new Time.desiredFps value and update based on the new Game core loop, rather than being bound to time calculations. This means that tweens are now running with the same update logic as physics and the core loop.
Tween.timeScale allows you to scale the duration of a tween (and any child tweens it may have). A value of 1.0 means it should play at the desiredFps rate. A value of 0.5 will run at half the frame rate, 2 at double and so on. You can even tween the timeScale value for interesting effects!
Tween.reverse allows you to instantly reverse an active tween. If the Tween has children then it will smoothly reverse through all child tweens as well.
Tween.repeatAll allows you to control how many times all child tweens will repeat before firing the Tween.onComplete event. You can set the value to -1 to repeat forever.
Tween.loop now controls the looping of all child tweens.
Tween.onRepeat is a new signal that is dispatched whenever a Tween repeats. If a Tween has many child tweens its dispatched once the sequence has repeated.
Tween.onChildComplete is a new signal that is dispatched whenever any child tweens have completed. If a Tween consists of 4 sections you will get 3 onChildComplete events followed by 1 onComplete event as the final tween finishes.
Chained tweens are now more intelligently handled. Because you can easily create child tweens (by simply calling Tween.to multiple times) chained tweens are now used to kick-off longer sequences. You can pass as many Tween objects to `Tween.chain` as you like as they'll all be played in sequence. As one Tween completes it passes on to the next until the entire chain is finished.
Tween.stop has a new `complete` parameter that if set will still fire the onComplete event and start the next chained tween, if there is one.
Tween.delay, Tween.repeat, Tween.yoyo, Tween.easing and Tween.interpolation all have a new `index` parameter. This allows you to target specific child tweens, or if set to -1 it will update all children at once.
Tween.totalDuration reports the total duration of all child tweens in ms.
There are new easing aliases:
* Phaser.Easing.Power0 = Phaser.Easing.Linear.None
* Phaser.Easing.Power1 = Phaser.Easing.Quadratic.Out
* Phaser.Easing.Power2 = Phaser.Easing.Cubic.Out
* Phaser.Easing.Power3 = Phaser.Easing.Quartic.Out
* Phaser.Easing.Power4 = Phaser.Easing.Quintic.Out
2014-11-20 06:04:54 +00:00
|
|
|
* If called directly the `Tween.onComplete` signal is not dispatched and no chained tweens are started unless the complete parameter is set to `true`.
|
2014-11-20 00:21:14 +00:00
|
|
|
* If you just wish to pause a tween then use Tween.pause instead.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#stop
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {boolean} [complete=false] - Set to `true` to dispatch the Tween.onComplete signal.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
stop: function (complete) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (complete === undefined) { complete = false; }
|
2013-08-28 23:09:12 +00:00
|
|
|
|
|
|
|
this.isRunning = false;
|
|
|
|
|
2014-02-05 02:39:03 +00:00
|
|
|
this._onUpdateCallback = null;
|
2014-11-20 00:21:14 +00:00
|
|
|
this._onUpdateCallbackContext = null;
|
|
|
|
|
|
|
|
if (complete)
|
|
|
|
{
|
2014-12-15 09:41:57 +00:00
|
|
|
this.onComplete.dispatch(this.target, this);
|
2015-11-11 17:39:05 +00:00
|
|
|
this._hasStarted = false;
|
Tweens have been completely rewritten. They're now much more flexible and efficient than before:
When specifying the ease in `Tween.to` or `Tween.from` you can now use a string instead of the Function. This makes your code less verbose. For example instead of `Phaser.Easing.Sinusoidal.Out` and you can now just use the string "Sine".The string names match those used by TweenMax and includes: "Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce", "Power0", "Power1", "Power2", "Power3" and "Power4". You can append ".easeIn", ".easeOut" and "easeInOut" variants. All are supported for each ease types.
Tweens now create a TweenData object. The Tween object itself acts like more of a timeline, managing multiple TweenData objects. You can now call `Tween.to` and each call will create a new child tween that is added to the timeline, which are played through in sequence.
Tweens are now bound to the new Time.desiredFps value and update based on the new Game core loop, rather than being bound to time calculations. This means that tweens are now running with the same update logic as physics and the core loop.
Tween.timeScale allows you to scale the duration of a tween (and any child tweens it may have). A value of 1.0 means it should play at the desiredFps rate. A value of 0.5 will run at half the frame rate, 2 at double and so on. You can even tween the timeScale value for interesting effects!
Tween.reverse allows you to instantly reverse an active tween. If the Tween has children then it will smoothly reverse through all child tweens as well.
Tween.repeatAll allows you to control how many times all child tweens will repeat before firing the Tween.onComplete event. You can set the value to -1 to repeat forever.
Tween.loop now controls the looping of all child tweens.
Tween.onRepeat is a new signal that is dispatched whenever a Tween repeats. If a Tween has many child tweens its dispatched once the sequence has repeated.
Tween.onChildComplete is a new signal that is dispatched whenever any child tweens have completed. If a Tween consists of 4 sections you will get 3 onChildComplete events followed by 1 onComplete event as the final tween finishes.
Chained tweens are now more intelligently handled. Because you can easily create child tweens (by simply calling Tween.to multiple times) chained tweens are now used to kick-off longer sequences. You can pass as many Tween objects to `Tween.chain` as you like as they'll all be played in sequence. As one Tween completes it passes on to the next until the entire chain is finished.
Tween.stop has a new `complete` parameter that if set will still fire the onComplete event and start the next chained tween, if there is one.
Tween.delay, Tween.repeat, Tween.yoyo, Tween.easing and Tween.interpolation all have a new `index` parameter. This allows you to target specific child tweens, or if set to -1 it will update all children at once.
Tween.totalDuration reports the total duration of all child tweens in ms.
There are new easing aliases:
* Phaser.Easing.Power0 = Phaser.Easing.Linear.None
* Phaser.Easing.Power1 = Phaser.Easing.Quadratic.Out
* Phaser.Easing.Power2 = Phaser.Easing.Cubic.Out
* Phaser.Easing.Power3 = Phaser.Easing.Quartic.Out
* Phaser.Easing.Power4 = Phaser.Easing.Quintic.Out
2014-11-20 06:04:54 +00:00
|
|
|
|
|
|
|
if (this.chainedTween)
|
|
|
|
{
|
|
|
|
this.chainedTween.start();
|
|
|
|
}
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
2014-02-05 02:39:03 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
this.manager.remove(this);
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-02-19 00:51:32 +00:00
|
|
|
* Updates either a single TweenData or all TweenData objects properties to the given value.
|
|
|
|
* Used internally by methods like Tween.delay, Tween.yoyo, etc. but can also be called directly if you know which property you want to tweak.
|
|
|
|
* The property is not checked, so if you pass an invalid one you'll generate a run-time error.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
2015-02-19 00:51:32 +00:00
|
|
|
* @method Phaser.Tween#updateTweenData
|
|
|
|
* @param {string} property - The property to update.
|
|
|
|
* @param {number|function} value - The value to set the property to.
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-02-19 00:51:32 +00:00
|
|
|
updateTweenData: function (property, value, index) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2014-12-07 11:31:48 +00:00
|
|
|
if (this.timeline.length === 0) { return this; }
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (index === undefined) { index = 0; }
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
if (index === -1)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
|
|
|
{
|
2015-02-19 00:51:32 +00:00
|
|
|
this.timeline[i][property] = value;
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-19 00:51:32 +00:00
|
|
|
this.timeline[index][property] = value;
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
2014-10-28 01:49:20 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
/**
|
|
|
|
* Sets the delay in milliseconds before this tween will start. If there are child tweens it sets the delay before the first child starts.
|
|
|
|
* The delay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
|
|
|
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to delay.
|
|
|
|
* If you have child tweens and pass -1 as the index value it sets the delay across all of them.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tween#delay
|
|
|
|
* @param {number} duration - The amount of time in ms that the Tween should wait until it begins once started is called. Set to zero to remove any active delay.
|
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children.
|
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
|
|
|
*/
|
|
|
|
delay: function (duration, index) {
|
|
|
|
|
|
|
|
return this.updateTweenData('delay', duration, index);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* Sets the number of times this tween will repeat.
|
2014-12-07 11:31:48 +00:00
|
|
|
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to repeat.
|
2014-11-20 00:21:14 +00:00
|
|
|
* If you have child tweens and pass -1 as the index value it sets the number of times they'll repeat across all of them.
|
|
|
|
* If you wish to define how many times this Tween and all children will repeat see Tween.repeatAll.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#repeat
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {number} total - How many times a tween should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
|
2015-02-19 00:51:32 +00:00
|
|
|
* @param {number} [repeat=0] - This is the amount of time to pause (in ms) before the repeat will start.
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeat value on all the children.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-02-19 00:51:32 +00:00
|
|
|
repeat: function (total, repeatDelay, index) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (repeatDelay === undefined) { repeatDelay = 0; }
|
2014-12-07 11:31:48 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
this.updateTweenData('repeatCounter', total, index);
|
2014-11-20 00:21:14 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
return this.updateTweenData('repeatDelay', repeatDelay, index);
|
2014-04-22 01:12:21 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the delay in milliseconds before this tween will repeat itself.
|
|
|
|
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
|
|
|
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
|
|
|
|
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tween#repeatDelay
|
|
|
|
* @param {number} duration - The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active repeatDelay.
|
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeatDelay on all the children.
|
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
|
|
|
*/
|
|
|
|
repeatDelay: function (duration, index) {
|
|
|
|
|
|
|
|
return this.updateTweenData('repeatDelay', duration, index);
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-18 20:58:25 +00:00
|
|
|
* A Tween that has yoyo set to true will run through from its starting values to its end values and then play back in reverse from end to start.
|
2013-11-25 04:40:04 +00:00
|
|
|
* Used in combination with repeat you can create endless loops.
|
2014-12-07 11:31:48 +00:00
|
|
|
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to yoyo.
|
2014-11-20 00:21:14 +00:00
|
|
|
* If you have child tweens and pass -1 as the index value it sets the yoyo property across all of them.
|
|
|
|
* If you wish to yoyo this Tween and all of its children then see Tween.yoyoAll.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#yoyo
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {boolean} enable - Set to true to yoyo this tween, or false to disable an already active yoyo.
|
2015-02-19 00:51:32 +00:00
|
|
|
* @param {number} [yoyoDelay=0] - This is the amount of time to pause (in ms) before the yoyo will start.
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set yoyo on all the children.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-02-19 00:51:32 +00:00
|
|
|
yoyo: function(enable, yoyoDelay, index) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (yoyoDelay === undefined) { yoyoDelay = 0; }
|
2014-12-07 11:31:48 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
this.updateTweenData('yoyo', enable, index);
|
2014-04-22 01:12:21 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
return this.updateTweenData('yoyoDelay', yoyoDelay, index);
|
2014-04-22 01:12:21 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the delay in milliseconds before this tween will run a yoyo (only applies if yoyo is enabled).
|
|
|
|
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
|
|
|
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
|
|
|
|
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tween#yoyoDelay
|
|
|
|
* @param {number} duration - The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active yoyoDelay.
|
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the yoyoDelay on all the children.
|
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
|
|
|
*/
|
|
|
|
yoyoDelay: function (duration, index) {
|
|
|
|
|
|
|
|
return this.updateTweenData('yoyoDelay', duration, index);
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-03-23 07:59:28 +00:00
|
|
|
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
2014-11-20 00:21:14 +00:00
|
|
|
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
|
|
|
|
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
|
|
|
|
* If you have child tweens and pass -1 as the index value it sets the easing function defined here across all of them.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#easing
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {function|string} ease - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
|
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the easing function on all children.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
easing: function (ease, index) {
|
|
|
|
|
|
|
|
if (typeof ease === 'string' && this.manager.easeMap[ease])
|
|
|
|
{
|
|
|
|
ease = this.manager.easeMap[ease];
|
|
|
|
}
|
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
return this.updateTweenData('easingFunction', ease, index);
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* Sets the interpolation function the tween will use. By default it uses Phaser.Math.linearInterpolation.
|
2013-12-30 16:54:00 +00:00
|
|
|
* Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation.
|
2014-11-20 00:21:14 +00:00
|
|
|
* The interpolation function is only used if the target properties is an array.
|
2015-02-16 12:23:54 +00:00
|
|
|
* If you have child tweens and pass -1 as the index value and it will set the interpolation function across all of them.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#interpolation
|
|
|
|
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
|
2015-02-19 00:51:32 +00:00
|
|
|
* @param {object} [context] - The context under which the interpolation function will be run.
|
2015-02-16 12:23:54 +00:00
|
|
|
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the interpolation function on all children.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-02-19 00:51:32 +00:00
|
|
|
interpolation: function (interpolation, context, index) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (context === undefined) { context = Phaser.Math; }
|
2014-11-20 00:21:14 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
this.updateTweenData('interpolationFunction', interpolation, index);
|
2014-11-20 00:21:14 +00:00
|
|
|
|
2015-02-19 00:51:32 +00:00
|
|
|
return this.updateTweenData('interpolationContext', context, index);
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set how many times this tween and all of its children will repeat.
|
|
|
|
* A tween (A) with 3 children (B,C,D) with a `repeatAll` value of 2 would play as: ABCDABCD before completing.
|
|
|
|
*
|
2016-04-05 00:06:05 +00:00
|
|
|
* @method Phaser.Tween#repeatAll
|
|
|
|
* @param {number} [total=0] - How many times this tween and all children should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
|
2014-11-20 00:21:14 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
|
|
|
*/
|
|
|
|
repeatAll: function (total) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (total === undefined) { total = 0; }
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
this.repeatCounter = total;
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-20 05:26:43 +00:00
|
|
|
* This method allows you to chain tweens together. Any tween chained to this tween will have its `Tween.start` method called
|
|
|
|
* as soon as this tween completes. If this tween never completes (i.e. repeatAll or loop is set) then the chain will never progress.
|
|
|
|
* Note that `Tween.onComplete` will fire when *this* tween completes, not when the whole chain completes.
|
|
|
|
* For that you should listen to `onComplete` on the final tween in your chain.
|
2015-05-09 00:42:29 +00:00
|
|
|
*
|
2014-11-20 05:26:43 +00:00
|
|
|
* If you pass multiple tweens to this method they will be joined into a single long chain.
|
|
|
|
* For example if this is Tween A and you pass in B, C and D then B will be chained to A, C will be chained to B and D will be chained to C.
|
|
|
|
* Any previously chained tweens that may have been set will be overwritten.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#chain
|
2014-11-20 05:26:43 +00:00
|
|
|
* @param {...Phaser.Tween} tweens - One or more tweens that will be chained to this one.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
|
|
|
chain: function () {
|
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
var i = arguments.length;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
arguments[i - 1].chainedTween = arguments[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.chainedTween = arguments[i];
|
|
|
|
}
|
|
|
|
}
|
2014-11-20 00:21:14 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-04-05 00:06:05 +00:00
|
|
|
* Enables the looping of this tween. The tween will loop forever, and onComplete will never fire.
|
|
|
|
*
|
2014-11-20 00:21:14 +00:00
|
|
|
* If `value` is `true` then this is the same as setting `Tween.repeatAll(-1)`.
|
|
|
|
* If `value` is `false` it is the same as setting `Tween.repeatAll(0)` and will reset the `repeatCounter` to zero.
|
2014-03-23 07:59:28 +00:00
|
|
|
*
|
2013-11-25 04:40:04 +00:00
|
|
|
* Usage:
|
|
|
|
* game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true)
|
|
|
|
* .to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
|
|
|
|
* .to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
|
|
|
|
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
|
|
|
|
* .loop();
|
|
|
|
* @method Phaser.Tween#loop
|
2016-04-05 00:06:05 +00:00
|
|
|
* @param {boolean} [value=true] - If `true` this tween will loop once it reaches the end. Set to `false` to remove an active loop.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-11-20 00:21:14 +00:00
|
|
|
loop: function (value) {
|
2014-11-18 20:58:25 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (value === undefined) { value = true; }
|
2014-11-18 20:58:25 +00:00
|
|
|
|
2016-04-05 00:06:05 +00:00
|
|
|
this.repeatCounter = (value) ? -1 : 0;
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-06-04 03:56:49 +00:00
|
|
|
* Sets a callback to be fired each time this tween updates.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#onUpdateCallback
|
2014-11-20 00:21:14 +00:00
|
|
|
* @param {function} callback - The callback to invoke each time this tween is updated. Set to `null` to remove an already active callback.
|
2014-06-04 03:56:49 +00:00
|
|
|
* @param {object} callbackContext - The context in which to call the onUpdate callback.
|
2014-10-28 01:49:20 +00:00
|
|
|
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-02-05 02:39:03 +00:00
|
|
|
onUpdateCallback: function (callback, callbackContext) {
|
2013-11-25 04:40:04 +00:00
|
|
|
|
|
|
|
this._onUpdateCallback = callback;
|
2014-02-05 02:39:03 +00:00
|
|
|
this._onUpdateCallbackContext = callbackContext;
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-20 00:21:14 +00:00
|
|
|
* Pauses the tween. Resume playback with Tween.resume.
|
2013-11-25 04:40:04 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#pause
|
|
|
|
*/
|
2013-10-03 01:38:35 +00:00
|
|
|
pause: function () {
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
this.isPaused = true;
|
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
this._codePaused = true;
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
this._pausedTime = this.game.time.time;
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2013-10-03 01:38:35 +00:00
|
|
|
},
|
2013-09-30 10:15:50 +00:00
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
/**
|
|
|
|
* This is called by the core Game loop. Do not call it directly, instead use Tween.pause.
|
2015-05-09 00:42:29 +00:00
|
|
|
*
|
2014-02-26 23:27:22 +00:00
|
|
|
* @private
|
2014-11-20 00:21:14 +00:00
|
|
|
* @method Phaser.Tween#_pause
|
2014-02-26 23:27:22 +00:00
|
|
|
*/
|
|
|
|
_pause: function () {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
if (!this._codePaused)
|
|
|
|
{
|
2014-11-20 00:21:14 +00:00
|
|
|
this.isPaused = true;
|
|
|
|
|
|
|
|
this._pausedTime = this.game.time.time;
|
2014-02-26 23:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Resumes a paused tween.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tween#resume
|
|
|
|
*/
|
2014-02-26 23:27:22 +00:00
|
|
|
resume: function () {
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
if (this.isPaused)
|
2014-02-25 03:33:47 +00:00
|
|
|
{
|
2014-11-20 00:21:14 +00:00
|
|
|
this.isPaused = false;
|
|
|
|
|
2014-02-26 23:27:22 +00:00
|
|
|
this._codePaused = false;
|
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
|
|
|
{
|
|
|
|
if (!this.timeline[i].isRunning)
|
|
|
|
{
|
|
|
|
this.timeline[i].startTime += (this.game.time.time - this._pausedTime);
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 03:33:47 +00:00
|
|
|
}
|
2014-02-26 23:27:22 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called by the core Game loop. Do not call it directly, instead use Tween.pause.
|
|
|
|
* @method Phaser.Tween#_resume
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_resume: function () {
|
|
|
|
|
|
|
|
if (this._codePaused)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-25 03:33:47 +00:00
|
|
|
else
|
|
|
|
{
|
2014-11-20 00:21:14 +00:00
|
|
|
this.resume();
|
2014-02-25 03:33:47 +00:00
|
|
|
}
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2013-10-03 01:38:35 +00:00
|
|
|
},
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tween#update
|
|
|
|
* @param {number} time - A timestamp passed in by the TweenManager.
|
2014-11-20 00:21:14 +00:00
|
|
|
* @return {boolean} false if the tween and all child tweens have completed and should be deleted from the manager, otherwise true (still active).
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-12-30 16:54:00 +00:00
|
|
|
update: function (time) {
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2016-04-04 21:06:06 +00:00
|
|
|
if (this.pendingDelete || !this.target)
|
2013-11-25 04:40:04 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-19 03:45:08 +00:00
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
if (this.isPaused)
|
2013-12-18 13:01:45 +00:00
|
|
|
{
|
2013-08-28 23:09:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
var status = this.timeline[this.current].update(time);
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
if (status === Phaser.TweenData.PENDING)
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-18 20:58:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (status === Phaser.TweenData.RUNNING)
|
|
|
|
{
|
2015-04-27 13:00:11 +00:00
|
|
|
if (!this._hasStarted)
|
|
|
|
{
|
|
|
|
this.onStart.dispatch(this.target, this);
|
|
|
|
this._hasStarted = true;
|
|
|
|
}
|
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
if (this._onUpdateCallback !== null)
|
|
|
|
{
|
|
|
|
this._onUpdateCallback.call(this._onUpdateCallbackContext, this, this.timeline[this.current].value, this.timeline[this.current]);
|
|
|
|
}
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
// In case the update callback modifies this tween
|
|
|
|
return this.isRunning;
|
|
|
|
}
|
|
|
|
else if (status === Phaser.TweenData.LOOPED)
|
|
|
|
{
|
2016-04-05 00:06:05 +00:00
|
|
|
if (this.timeline[this.current].repeatCounter === -1)
|
2016-02-17 02:57:45 +00:00
|
|
|
{
|
|
|
|
this.onLoop.dispatch(this.target, this);
|
|
|
|
}
|
2016-04-05 00:11:50 +00:00
|
|
|
else
|
2016-02-17 02:57:45 +00:00
|
|
|
{
|
|
|
|
this.onRepeat.dispatch(this.target, this);
|
|
|
|
}
|
2016-04-05 00:06:05 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (status === Phaser.TweenData.COMPLETE)
|
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
var complete = false;
|
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
// What now?
|
|
|
|
if (this.reverse)
|
|
|
|
{
|
|
|
|
this.current--;
|
2014-11-20 02:17:41 +00:00
|
|
|
|
|
|
|
if (this.current < 0)
|
|
|
|
{
|
|
|
|
this.current = this.timeline.length - 1;
|
|
|
|
complete = true;
|
|
|
|
}
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
|
|
|
else
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-18 20:58:25 +00:00
|
|
|
this.current++;
|
2014-11-20 02:17:41 +00:00
|
|
|
|
|
|
|
if (this.current === this.timeline.length)
|
|
|
|
{
|
|
|
|
this.current = 0;
|
|
|
|
complete = true;
|
|
|
|
}
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-20 02:17:41 +00:00
|
|
|
if (complete)
|
2014-11-20 00:21:14 +00:00
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
// We've reached the start or end of the child tweens (depending on Tween.reverse), should we repeat it?
|
|
|
|
if (this.repeatCounter === -1)
|
2014-11-20 00:21:14 +00:00
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
this.timeline[this.current].start();
|
2016-02-17 02:57:45 +00:00
|
|
|
this.onLoop.dispatch(this.target, this);
|
2014-11-20 02:17:41 +00:00
|
|
|
return true;
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
2014-11-20 02:17:41 +00:00
|
|
|
else if (this.repeatCounter > 0)
|
2014-11-20 00:21:14 +00:00
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
this.repeatCounter--;
|
|
|
|
|
|
|
|
this.timeline[this.current].start();
|
|
|
|
this.onRepeat.dispatch(this.target, this);
|
|
|
|
return true;
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
2014-11-20 02:17:41 +00:00
|
|
|
else
|
2014-11-20 00:21:14 +00:00
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
// No more repeats and no more children, so we're done
|
|
|
|
this.isRunning = false;
|
|
|
|
this.onComplete.dispatch(this.target, this);
|
2015-11-11 17:39:05 +00:00
|
|
|
this._hasStarted = false;
|
2014-11-20 05:26:43 +00:00
|
|
|
|
|
|
|
if (this.chainedTween)
|
|
|
|
{
|
|
|
|
this.chainedTween.start();
|
|
|
|
}
|
|
|
|
|
2014-11-20 02:17:41 +00:00
|
|
|
return false;
|
2014-11-20 00:21:14 +00:00
|
|
|
}
|
2013-12-30 16:54:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-20 02:17:41 +00:00
|
|
|
// We've still got some children to go
|
|
|
|
this.onChildComplete.dispatch(this.target, this);
|
|
|
|
this.timeline[this.current].start();
|
|
|
|
return true;
|
2014-11-18 20:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
},
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-18 20:58:25 +00:00
|
|
|
/**
|
|
|
|
* This will generate an array populated with the tweened object values from start to end.
|
2014-11-24 12:34:42 +00:00
|
|
|
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
|
|
|
|
* It ignores delay and repeat counts and any chained tweens, but does include child tweens.
|
|
|
|
* Just one play through of the tween data is returned, including yoyo if set.
|
2014-11-18 20:58:25 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tween#generateData
|
|
|
|
* @param {number} [frameRate=60] - The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates.
|
|
|
|
* @param {array} [data] - If given the generated data will be appended to this array, otherwise a new array will be returned.
|
|
|
|
* @return {array} An array of tweened values.
|
2014-11-24 12:34:42 +00:00
|
|
|
*/
|
2014-11-18 20:58:25 +00:00
|
|
|
generateData: function (frameRate, data) {
|
|
|
|
|
|
|
|
if (this.game === null || this.target === null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-04-05 00:06:05 +00:00
|
|
|
if (frameRate === undefined) { frameRate = 60; }
|
|
|
|
if (data === undefined) { data = []; }
|
2014-11-18 20:58:25 +00:00
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
// Populate the tween data
|
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-24 12:34:42 +00:00
|
|
|
// Build our master property list with the starting values
|
|
|
|
for (var property in this.timeline[i].vEnd)
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-24 12:34:42 +00:00
|
|
|
this.properties[property] = this.target[property] || 0;
|
2014-11-18 20:58:25 +00:00
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
if (!Array.isArray(this.properties[property]))
|
2013-12-30 16:54:00 +00:00
|
|
|
{
|
2014-11-24 12:34:42 +00:00
|
|
|
// Ensures we're using numbers, not strings
|
|
|
|
this.properties[property] *= 1.0;
|
2014-05-01 01:40:36 +00:00
|
|
|
}
|
2014-11-18 20:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
2014-11-18 20:58:25 +00:00
|
|
|
{
|
2014-11-24 12:34:42 +00:00
|
|
|
this.timeline[i].loadValues();
|
2014-11-18 20:58:25 +00:00
|
|
|
}
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
2014-11-18 20:58:25 +00:00
|
|
|
{
|
2014-11-24 12:34:42 +00:00
|
|
|
data = data.concat(this.timeline[i].generateData(frameRate));
|
2013-11-25 04:40:04 +00:00
|
|
|
}
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2014-11-24 12:34:42 +00:00
|
|
|
return data;
|
2013-08-28 23:09:12 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-28 23:09:12 +00:00
|
|
|
};
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2014-11-20 00:21:14 +00:00
|
|
|
/**
|
2014-11-20 05:26:43 +00:00
|
|
|
* @name Phaser.Tween#totalDuration
|
|
|
|
* @property {Phaser.TweenData} totalDuration - Gets the total duration of this Tween, including all child tweens, in milliseconds.
|
2014-11-20 00:21:14 +00:00
|
|
|
*/
|
2014-11-20 05:26:43 +00:00
|
|
|
Object.defineProperty(Phaser.Tween.prototype, 'totalDuration', {
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
2014-11-20 05:26:43 +00:00
|
|
|
var total = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.timeline.length; i++)
|
|
|
|
{
|
|
|
|
total += this.timeline[i].duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
2014-11-20 00:21:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
Phaser.Tween.prototype.constructor = Phaser.Tween;
|