Skip to content

Commit 224553e

Browse files
committed
Phaser.Tween.from
Added a reverse tweening function that will accept properties of where you want to start the tween from and will end the tween at the current property or properties that are passed in. Usage: ```language-javascript var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'yeoman'); game.add.tween(sprite).from({x: 0 - sprite.width}, 1000, Phaser.Easing.Bounce.Out, true); ```
1 parent afc4f17 commit 224553e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/tween/Tween.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ Phaser.Tween.prototype = {
259259

260260
},
261261

262+
/**
263+
* Configure a Reverse Tween
264+
*
265+
* @method Phaser.Tween#from
266+
* @param {object} properties - Properties you want to tween from.
267+
* @param {number} [duration=1000] - Duration of this tween in ms.
268+
* @param {function} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Linear.None.
269+
* @param {boolean} [autoStart=false] - Whether this tween will start automatically or not.
270+
* @param {number} [delay=0] - Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
271+
* @param {number} [repeat=0] - Should the tween automatically restart once complete? If you want it to run forever set as Number.MAX_VALUE. This ignores any chained tweens.
272+
* @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.
273+
* @return {Phaser.Tween} This Tween object.
274+
*/
275+
from: function(properties, duration, ease, autoStart, delay, repeat, yoyo) {
276+
var _cache = {};
277+
for(var prop in properties) {
278+
if (properties.hasOwnProperty(prop)) {
279+
_cache[prop] = this._object[prop];
280+
this._object[prop] = properties[prop];
281+
}
282+
}
283+
this.to(_cache, duration, ease, autoStart, delay, repeat, yoyo);
284+
},
285+
262286
/**
263287
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
264288
*

0 commit comments

Comments
 (0)