make tweens chain loopable

This commit is contained in:
powerfear
2013-09-20 21:47:58 -04:00
parent f31d56584d
commit c36543a261
2 changed files with 20 additions and 6 deletions
+2 -5
View File
@@ -10,7 +10,6 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
var p;
var p2;
function preload() {
@@ -27,13 +26,11 @@
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);
.to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
.loop();
}
function update() {
// p.y = game.math.min(100, game.input.y);
}
function render() {
+18 -1
View File
@@ -76,7 +76,7 @@ Phaser.Tween.prototype = {
if (this._parent)
{
self = this._manager.create(this._object);
self._parent = this;
self._parent = this._parent;
this.chain(self);
}
else
@@ -206,6 +206,23 @@ Phaser.Tween.prototype = {
},
/**
* Loop a chain of tweens
*
* 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();
*
* @return {Tween} Itself.
*/
loop: function() {
if (this._parent) this.chain(this._parent);
return this;
},
onStartCallback: function ( callback ) {
this._onStartCallback = callback;