2013-08-28 20:29:25 +00:00
|
|
|
/**
|
|
|
|
* Phaser - TweenManager
|
|
|
|
*
|
|
|
|
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
|
|
|
|
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
|
|
|
|
*
|
|
|
|
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
|
|
|
|
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
|
|
|
|
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
|
|
|
|
* Please see https://github.com/sole/tween.js for a full list of contributors.
|
|
|
|
*/
|
|
|
|
Phaser.TweenManager = function (game) {
|
|
|
|
|
|
|
|
this.game = game;
|
|
|
|
this._tweens = [];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.TweenManager.prototype = {
|
|
|
|
|
|
|
|
REVISION: '11dev',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the tween objects in an array.
|
|
|
|
* @return {Phaser.Tween[]} Array with all tween objects.
|
|
|
|
*/
|
|
|
|
getAll: function () {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
return this._tweens;
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all tween objects.
|
|
|
|
*/
|
|
|
|
removeAll: function () {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
this._tweens = [];
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new tween into the TweenManager.
|
|
|
|
*
|
|
|
|
* @param tween {Phaser.Tween} The tween object you want to add.
|
|
|
|
* @return {Phaser.Tween} The tween object you added to the manager.
|
|
|
|
*/
|
|
|
|
add: function ( tween ) {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
this._tweens.push( tween );
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
|
|
|
*
|
|
|
|
* @param obj {object} Object the tween will be run on.
|
|
|
|
* @return {Phaser.Tween} The newly created tween object.
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
create: function (object) {
|
|
|
|
|
|
|
|
return new Phaser.Tween(object, this.game);
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a tween from this manager.
|
|
|
|
*
|
|
|
|
* @param tween {Phaser.Tween} The tween object you want to remove.
|
|
|
|
*/
|
|
|
|
remove: function ( tween ) {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
var i = this._tweens.indexOf( tween );
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
if ( i !== -1 ) {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
this._tweens.splice( i, 1 );
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update all the tween objects you added to this manager.
|
|
|
|
*
|
|
|
|
* @return {bool} Return false if there's no tween to update, otherwise return true.
|
|
|
|
*/
|
2013-08-28 23:09:12 +00:00
|
|
|
update: function () {
|
2013-08-28 20:29:25 +00:00
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
if ( this._tweens.length === 0 ) return false;
|
2013-08-28 20:29:25 +00:00
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
var i = 0, numTweens = this._tweens.length;
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
while ( i < numTweens ) {
|
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
if ( this._tweens[ i ].update( this.game.time.now ) ) {
|
2013-08-28 20:29:25 +00:00
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
i++;
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
this._tweens.splice( i, 1 );
|
2013-08-28 20:29:25 +00:00
|
|
|
|
2013-08-29 06:06:16 +00:00
|
|
|
numTweens--;
|
2013-08-28 20:29:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pauses all currently running tweens.
|
|
|
|
*/
|
|
|
|
pauseAll: function () {
|
|
|
|
|
|
|
|
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
|
|
|
this._tweens[i].pause();
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pauses all currently paused tweens.
|
|
|
|
*/
|
|
|
|
resumeAll: function () {
|
|
|
|
|
|
|
|
for (var i = this._tweens.length - 1; i >= 0; i--) {
|
|
|
|
this._tweens[i].resume();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|