mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
A TweenData wouldn't take into account the repeatDelay
property when repeating the tween, but now does. A TweenData also has a new property yoyoDelay
which controls the delay before the yoyo will start, allowing you to set both independently (thanks @DreadKnight #1469)
Tween.updateTweenData allows you to set a property to the given value across one or all of the current tweens. All of the Tween methods like Tween.delay and Tween.repeat have been updated to use this. Tween.repeat has a new parameter `repeatDelay` which allows you to set the delay (in ms) before a tween will repeat itself. Tween.yoyo has a new parameter `yoyoDelay` which allows you to set the delay (in ms) before a tween will start a yoyo. Tween.interpolation has a new parameter `context` which allows you to define the context in which the interpolation function will run.
This commit is contained in:
parent
35b4926eb8
commit
02ef1555c5
3 changed files with 115 additions and 87 deletions
|
@ -153,6 +153,10 @@ We've also removed functions and properties from Pixi classes that Phaser doesn'
|
|||
* If you load an image and provide a key that was already in-use in the Cache, then the old image is now destroyed (via `Cache.removeImage`) and the new image takes its place.
|
||||
* BitmapText has a new `maxWidth` property that will attempt to wrap the text if it exceeds the width specified.
|
||||
* Group.cursorIndex is the index of the item the Group cursor points to. This replaces Group._cache[8].
|
||||
* Tween.updateTweenData allows you to set a property to the given value across one or all of the current tweens. All of the Tween methods like Tween.delay and Tween.repeat have been updated to use this.
|
||||
* Tween.repeat has a new parameter `repeatDelay` which allows you to set the delay (in ms) before a tween will repeat itself.
|
||||
* Tween.yoyo has a new parameter `yoyoDelay` which allows you to set the delay (in ms) before a tween will start a yoyo.
|
||||
* Tween.interpolation has a new parameter `context` which allows you to define the context in which the interpolation function will run.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
@ -180,8 +184,9 @@ We've also removed functions and properties from Pixi classes that Phaser doesn'
|
|||
* World.setBounds if called after you had already started P2 Physics would incorrectly create a new collision group for the wall objects. P2.World now remembers the settings you provide for each wall and the collision group, and re-applies these settings should the world dimensions ever change (thanks @nextht #1455)
|
||||
* InputHandler was using the wrong property in `checkBoundsSprite` when fixedToCamera (thanks @yig #1613)
|
||||
* Tween.to now correctly accepts arrays are destination values, which makes the Tween interpolate through each value specified in the array using the defined Tween.interpolation method (see new example, thanks @FridayMarch26th #1619)
|
||||
* Tween.interpolationFunction was using the incorrect context to invoke the function. This is now defined in `TweenData.interpolationFunctionContext` and defaults to `Phaser.Math`. If you provide your own interpolation function then please adjust the context accordingly (thanks @FridayMarch26th #1618)
|
||||
* Tween.interpolationFunction was using the incorrect context to invoke the function. This is now defined in `TweenData.interpolationContext` and defaults to `Phaser.Math`. If you provide your own interpolation function then please adjust the context accordingly (thanks @FridayMarch26th #1618)
|
||||
* Graphics.drawEllipse method was missing (thanks @jackrugile #1574)
|
||||
* A TweenData wouldn't take into account the `repeatDelay` property when repeating the tween, but now does. A TweenData also has a new property `yoyoDelay` which controls the delay before the yoyo will start, allowing you to set both independently (thanks @DreadKnight #1469)
|
||||
|
||||
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
|
||||
|
||||
|
|
|
@ -62,11 +62,6 @@ Phaser.Tween = function (target, game, manager) {
|
|||
*/
|
||||
this.repeatCounter = 0;
|
||||
|
||||
/**
|
||||
* @property {number} repeatDelay - The amount of time in ms between repeats of this tween and any child tweens.
|
||||
*/
|
||||
this.repeatDelay = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} pendingDelete - True if this Tween is ready to be deleted by the TweenManager.
|
||||
* @default
|
||||
|
@ -356,6 +351,39 @@ Phaser.Tween.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates either a single TweenData or all TweenData objects properties to the given value.
|
||||
* Used internally by methods like Tween.delay, Tween.yoyo, etc. but can also be called directly if you know which property you want to tweak.
|
||||
* The property is not checked, so if you pass an invalid one you'll generate a run-time error.
|
||||
*
|
||||
* @method Phaser.Tween#updateTweenData
|
||||
* @param {string} property - The property to update.
|
||||
* @param {number|function} value - The value to set the property to.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
updateTweenData: function (property, value, index) {
|
||||
|
||||
if (this.timeline.length === 0) { return this; }
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i][property] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index][property] = value;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the delay in milliseconds before this tween will start. If there are child tweens it sets the delay before the first child starts.
|
||||
* The delay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
||||
|
@ -369,23 +397,7 @@ Phaser.Tween.prototype = {
|
|||
*/
|
||||
delay: function (duration, index) {
|
||||
|
||||
if (this.timeline.length === 0) { return this; }
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i].delay = duration;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index].delay = duration;
|
||||
}
|
||||
|
||||
return this;
|
||||
return this.updateTweenData('delay', duration, index);
|
||||
|
||||
},
|
||||
|
||||
|
@ -397,28 +409,34 @@ Phaser.Tween.prototype = {
|
|||
*
|
||||
* @method Phaser.Tween#repeat
|
||||
* @param {number} total - How many times a tween should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
|
||||
* @param {number} [repeat=0] - This is the amount of time to pause (in ms) before the repeat will start.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeat value on all the children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
repeat: function (total, index) {
|
||||
repeat: function (total, repeatDelay, index) {
|
||||
|
||||
if (this.timeline.length === 0) { return this; }
|
||||
if (typeof repeatDelay === 'undefined') { repeatDelay = 0; }
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
this.updateTweenData('repeatCounter', total, index);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i].repeatCounter = total;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index].repeatCounter = total;
|
||||
}
|
||||
return this.updateTweenData('repeatDelay', repeatDelay, index);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the delay in milliseconds before this tween will repeat itself.
|
||||
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
||||
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
|
||||
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
|
||||
*
|
||||
* @method Phaser.Tween#repeatDelay
|
||||
* @param {number} duration - The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active repeatDelay.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeatDelay on all the children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
repeatDelay: function (duration, index) {
|
||||
|
||||
return this.updateTweenData('repeatDelay', duration, index);
|
||||
|
||||
},
|
||||
|
||||
|
@ -431,28 +449,34 @@ Phaser.Tween.prototype = {
|
|||
*
|
||||
* @method Phaser.Tween#yoyo
|
||||
* @param {boolean} enable - Set to true to yoyo this tween, or false to disable an already active yoyo.
|
||||
* @param {number} [yoyoDelay=0] - This is the amount of time to pause (in ms) before the yoyo will start.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set yoyo on all the children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
yoyo: function(enable, index) {
|
||||
yoyo: function(enable, yoyoDelay, index) {
|
||||
|
||||
if (this.timeline.length === 0) { return this; }
|
||||
if (typeof yoyoDelay === 'undefined') { yoyoDelay = 0; }
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
this.updateTweenData('yoyo', enable, index);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i].yoyo = enable;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index].yoyo = enable;
|
||||
}
|
||||
return this.updateTweenData('yoyoDelay', yoyoDelay, index);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the delay in milliseconds before this tween will run a yoyo (only applies if yoyo is enabled).
|
||||
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
|
||||
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
|
||||
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
|
||||
*
|
||||
* @method Phaser.Tween#yoyoDelay
|
||||
* @param {number} duration - The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active yoyoDelay.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the yoyoDelay on all the children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
yoyoDelay: function (duration, index) {
|
||||
|
||||
return this.updateTweenData('yoyoDelay', duration, index);
|
||||
|
||||
},
|
||||
|
||||
|
@ -469,26 +493,12 @@ Phaser.Tween.prototype = {
|
|||
*/
|
||||
easing: function (ease, index) {
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
|
||||
if (typeof ease === 'string' && this.manager.easeMap[ease])
|
||||
{
|
||||
ease = this.manager.easeMap[ease];
|
||||
}
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i].easingFunction = ease;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index].easingFunction = ease;
|
||||
}
|
||||
|
||||
return this;
|
||||
return this.updateTweenData('easingFunction', ease, index);
|
||||
|
||||
},
|
||||
|
||||
|
@ -500,26 +510,17 @@ Phaser.Tween.prototype = {
|
|||
*
|
||||
* @method Phaser.Tween#interpolation
|
||||
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
|
||||
* @param {object} [context] - The context under which the interpolation function will be run.
|
||||
* @param {number} [index=0] - If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the interpolation function on all children.
|
||||
* @return {Phaser.Tween} This tween. Useful for method chaining.
|
||||
*/
|
||||
interpolation: function (interpolation, index) {
|
||||
interpolation: function (interpolation, context, index) {
|
||||
|
||||
if (typeof index === 'undefined') { index = 0; }
|
||||
if (typeof context === 'undefined') { context = Phaser.Math; }
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
for (var i = 0; i < this.timeline.length; i++)
|
||||
{
|
||||
this.timeline[i].interpolationFunction = interpolation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.timeline[index].interpolationFunction = interpolation;
|
||||
}
|
||||
this.updateTweenData('interpolationFunction', interpolation, index);
|
||||
|
||||
return this;
|
||||
return this.updateTweenData('interpolationContext', context, index);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -89,6 +89,11 @@ Phaser.TweenData = function (parent) {
|
|||
*/
|
||||
this.yoyo = false;
|
||||
|
||||
/**
|
||||
* @property {number} yoyoDelay - The amount of time in ms between yoyos of this tween.
|
||||
*/
|
||||
this.yoyoDelay = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} inReverse - When a Tween is yoyoing this value holds if it's currently playing forwards (false) or in reverse (true).
|
||||
* @default
|
||||
|
@ -96,7 +101,7 @@ Phaser.TweenData = function (parent) {
|
|||
this.inReverse = false;
|
||||
|
||||
/**
|
||||
* @property {number} delay - The amount to delay by until the Tween starts (in ms).
|
||||
* @property {number} delay - The amount to delay by until the Tween starts (in ms). Only applies to the start, use repeatDelay to handle repeats.
|
||||
* @default
|
||||
*/
|
||||
this.delay = 0;
|
||||
|
@ -124,10 +129,10 @@ Phaser.TweenData = function (parent) {
|
|||
this.interpolationFunction = Phaser.Math.linearInterpolation;
|
||||
|
||||
/**
|
||||
* @property {object} interpolationFunctionContext - The interpolation function context used for the Tween.
|
||||
* @property {object} interpolationContext - The interpolation function context used for the Tween.
|
||||
* @default Phaser.Math
|
||||
*/
|
||||
this.interpolationFunctionContext = Phaser.Math;
|
||||
this.interpolationContext = Phaser.Math;
|
||||
|
||||
/**
|
||||
* @property {boolean} isRunning - If the tween is running this is set to `true`. Unless Phaser.Tween a TweenData that is waiting for a delay to expire is *not* considered as running.
|
||||
|
@ -341,6 +346,14 @@ Phaser.TweenData.prototype = {
|
|||
return Phaser.TweenData.PENDING;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is Running, but is waiting to repeat
|
||||
if (this.game.time.time < this.startTime)
|
||||
{
|
||||
return Phaser.TweenData.RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.parent.reverse)
|
||||
{
|
||||
|
@ -364,7 +377,7 @@ Phaser.TweenData.prototype = {
|
|||
|
||||
if (Array.isArray(end))
|
||||
{
|
||||
this.parent.target[property] = this.interpolationFunction.call(this.interpolationFunctionContext, end, this.value);
|
||||
this.parent.target[property] = this.interpolationFunction.call(this.interpolationContext, end, this.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -513,7 +526,16 @@ Phaser.TweenData.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
this.startTime = this.game.time.time + this.delay;
|
||||
this.startTime = this.game.time.time;
|
||||
|
||||
if (this.yoyo && this.inReverse)
|
||||
{
|
||||
this.startTime += this.yoyoDelay;
|
||||
}
|
||||
else if (!this.inReverse)
|
||||
{
|
||||
this.startTime += this.repeatDelay;
|
||||
}
|
||||
|
||||
if (this.parent.reverse)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue