From c36543a2614977dc97b7adefe27e9653948f2598 Mon Sep 17 00:00:00 2001 From: powerfear Date: Fri, 20 Sep 2013 21:47:58 -0400 Subject: [PATCH] make tweens chain loopable --- examples/tweens/chained tweens.php | 7 ++----- src/tween/Tween.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/tweens/chained tweens.php b/examples/tweens/chained tweens.php index 2b4ce086..cb77634f 100644 --- a/examples/tweens/chained tweens.php +++ b/examples/tweens/chained tweens.php @@ -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() { diff --git a/src/tween/Tween.js b/src/tween/Tween.js index e4986732..e1161377 100644 --- a/src/tween/Tween.js +++ b/src/tween/Tween.js @@ -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;