mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Merge pull request #61 from powerfear/master
make tweens chainable with .to
This commit is contained in:
commit
f66e6326e3
2 changed files with 83 additions and 8 deletions
44
examples/tweens/chained tweens.php
Normal file
44
examples/tweens/chained tweens.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
$title = "Chained Tweens";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
var p;
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('diamond', 'assets/sprites/diamond.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = 0x337799;
|
||||
|
||||
p = game.add.sprite(0, 0, 'diamond');
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
|
@ -35,6 +35,7 @@ Phaser.Tween = function (object, game) {
|
|||
this._onCompleteCallback = null;
|
||||
|
||||
this._pausedTime = 0;
|
||||
this._parent = null;
|
||||
|
||||
this.pendingDelete = false;
|
||||
|
||||
|
@ -71,26 +72,39 @@ Phaser.Tween.prototype = {
|
|||
repeat = repeat || 0;
|
||||
yoyo = yoyo || false;
|
||||
|
||||
this._repeat = repeat;
|
||||
this._duration = duration;
|
||||
this._valuesEnd = properties;
|
||||
var self;
|
||||
if (this._parent)
|
||||
{
|
||||
self = this._manager.create(this._object);
|
||||
self._parent = this._parent;
|
||||
this.chain(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = this;
|
||||
self._parent = self;
|
||||
}
|
||||
|
||||
self._repeat = repeat;
|
||||
self._duration = duration;
|
||||
self._valuesEnd = properties;
|
||||
|
||||
if (ease !== null)
|
||||
{
|
||||
this._easingFunction = ease;
|
||||
self._easingFunction = ease;
|
||||
}
|
||||
|
||||
if (delay > 0)
|
||||
{
|
||||
this._delayTime = delay;
|
||||
self._delayTime = delay;
|
||||
}
|
||||
|
||||
this._yoyo = yoyo;
|
||||
self._yoyo = yoyo;
|
||||
|
||||
if (autoStart) {
|
||||
return this.start();
|
||||
return self.start();
|
||||
} else {
|
||||
return this;
|
||||
return self;
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -192,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;
|
||||
|
|
Loading…
Reference in a new issue