TweenData.repeatTotal is a new property that keeps track of the total number of times the Tween should repeat. If TweenData.start is called, as a result of the Tween repeatCount being > 0 then the child tween resets its total before re-starting.

This commit is contained in:
photonstorm 2016-04-05 01:06:05 +01:00
parent f9949166be
commit 917d9c7060
3 changed files with 24 additions and 26 deletions

View file

@ -338,7 +338,8 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Ensure a parent container is a Group before removing from its hash (thanks @rblopes #2397)
* The Game Object Input Handler now checks to see if the Object was destroyed during the `onInputDown` phase, and bails out early if so (thanks @zeterain #2394)
* The Destroy component will now call TweenManager.removeFrom, removing any active tweens from the TweenManager upon the Game Objects destructions (thanks @PokemonAshLovesMyTurkeyAndILikeYouTwo #2408)
* Tween.update will now return `false` (flagging the Tween for destruction) should the Tween.target property every become falsey. This can happen if the object the Tween was tracking is destroyed, nulled or generally removed..
* Tween.update will now return `false` (flagging the Tween for destruction) should the Tween.target property every become falsey. This can happen if the object the Tween was tracking is destroyed, nulled or generally removed.
* TweenData.repeatTotal is a new property that keeps track of the total number of times the Tween should repeat. If TweenData.start is called, as a result of the Tween repeatCount being > 0 then the child tween resets its total before re-starting.
### Bug Fixes

View file

@ -77,8 +77,9 @@ Phaser.Tween = function (target, game, manager) {
this.onStart = new Phaser.Signal();
/**
* The onLoop event is fired if the Tween or any child tween loops.
* The onLoop event is fired if the Tween, or any child tweens loop.
* It will be sent 2 parameters: the target object and this tween.
*
* @property {Phaser.Signal} onLoop
*/
this.onLoop = new Phaser.Signal();
@ -547,10 +548,9 @@ Phaser.Tween.prototype = {
/**
* Set how many times this tween and all of its children will repeat.
* A tween (A) with 3 children (B,C,D) with a `repeatAll` value of 2 would play as: ABCDABCD before completing.
* When all child tweens have completed Tween.onLoop will be dispatched.
*
* @method Phaser.Tween#repeat
* @param {number} total - How many times this tween and all children should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
* @method Phaser.Tween#repeatAll
* @param {number} [total=0] - How many times this tween and all children should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
* @return {Phaser.Tween} This tween. Useful for method chaining.
*/
repeatAll: function (total) {
@ -598,7 +598,8 @@ Phaser.Tween.prototype = {
},
/**
* Enables the looping of this tween and all child tweens. If this tween has no children this setting has no effect.
* Enables the looping of this tween. The tween will loop forever, and onComplete will never fire.
*
* If `value` is `true` then this is the same as setting `Tween.repeatAll(-1)`.
* If `value` is `false` it is the same as setting `Tween.repeatAll(0)` and will reset the `repeatCounter` to zero.
*
@ -609,21 +610,14 @@ Phaser.Tween.prototype = {
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
* .loop();
* @method Phaser.Tween#loop
* @param {boolean} [value=true] - If `true` this tween and any child tweens will loop once they reach the end. Set to `false` to remove an active loop.
* @param {boolean} [value=true] - If `true` this tween will loop once it reaches the end. Set to `false` to remove an active loop.
* @return {Phaser.Tween} This tween. Useful for method chaining.
*/
loop: function (value) {
if (value === undefined) { value = true; }
if (value)
{
this.repeatAll(-1);
}
else
{
this.repeatCounter = 0;
}
this.repeatCounter = (value) ? -1 : 0;
return this;
@ -763,14 +757,15 @@ Phaser.Tween.prototype = {
}
else if (status === Phaser.TweenData.LOOPED)
{
if (this.repeatCounter === -1)
if (this.timeline[this.current].repeatCounter === -1)
{
this.onLoop.dispatch(this.target, this);
}
else
else if (this.timeline[this.current].repeatCounter > 0)
{
this.onRepeat.dispatch(this.target, this);
}
return true;
}
else if (status === Phaser.TweenData.COMPLETE)
@ -860,13 +855,8 @@ Phaser.Tween.prototype = {
return null;
}
if (frameRate === undefined) {
frameRate = 60;
}
if (data === undefined) {
data = [];
}
if (frameRate === undefined) { frameRate = 60; }
if (data === undefined) { data = []; }
// Populate the tween data
for (var i = 0; i < this.timeline.length; i++)

View file

@ -77,6 +77,12 @@ Phaser.TweenData = function (parent) {
*/
this.repeatDelay = 0;
/**
* @property {number} repeatTotal - The total number of times this Tween will repeat.
* @readonly
*/
this.repeatTotal = 0;
/**
* @property {boolean} interpolate - True if the Tween will use interpolation (i.e. is an Array to Array tween)
* @default
@ -193,7 +199,7 @@ Phaser.TweenData.prototype = {
this.duration = duration;
this.easingFunction = ease;
this.delay = delay;
this.repeatCounter = repeat;
this.repeatTotal = repeat;
this.yoyo = yoyo;
this.isFrom = false;
@ -221,7 +227,7 @@ Phaser.TweenData.prototype = {
this.duration = duration;
this.easingFunction = ease;
this.delay = delay;
this.repeatCounter = repeat;
this.repeatTotal = repeat;
this.yoyo = yoyo;
this.isFrom = true;
@ -271,6 +277,7 @@ Phaser.TweenData.prototype = {
this.value = 0;
this.yoyoCounter = 0;
this.repeatCounter = this.repeatTotal;
return this;