Skip to content

Commit 01a23b7

Browse files
committed
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 phaserjs#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 phaserjs#1618)
1 parent ae198e9 commit 01a23b7

4 files changed

Lines changed: 35 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Thanks to @pnstickne for vast majority of this update.
156156
* PIXI.WebGLRenderer.destroy has been fixed to decrement the `glContextId` and remove it from the PIXI.instances global. `Game.destroy` now hooks into this. This now means that you can now delete and create your Phaser game over and over without it crashing WebGL after the 4th attempt (#1260)
157157
* 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)
158158
* InputHandler was using the wrong property in `checkBoundsSprite` when fixedToCamera (thanks @yig #1613)
159+
* 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)
160+
* 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)
159161

160162
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
161163

src/math/Math.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,11 @@ Phaser.Math = {
763763

764764
/**
765765
* A Linear Interpolation Method, mostly used by Phaser.Tween.
766+
*
766767
* @method Phaser.Math#linearInterpolation
767-
* @param {Array} v
768-
* @param {number} k
769-
* @return {number}
768+
* @param {Array} v - The input array of values to interpolate between.
769+
* @param {number} k - The percentage of interpolation, between 0 and 1.
770+
* @return {number} The interpolated value
770771
*/
771772
linearInterpolation: function (v, k) {
772773

@@ -790,10 +791,11 @@ Phaser.Math = {
790791

791792
/**
792793
* A Bezier Interpolation Method, mostly used by Phaser.Tween.
794+
*
793795
* @method Phaser.Math#bezierInterpolation
794-
* @param {Array} v
795-
* @param {number} k
796-
* @return {number}
796+
* @param {Array} v - The input array of values to interpolate between.
797+
* @param {number} k - The percentage of interpolation, between 0 and 1.
798+
* @return {number} The interpolated value
797799
*/
798800
bezierInterpolation: function (v, k) {
799801

@@ -811,10 +813,11 @@ Phaser.Math = {
811813

812814
/**
813815
* A Catmull Rom Interpolation Method, mostly used by Phaser.Tween.
816+
*
814817
* @method Phaser.Math#catmullRomInterpolation
815-
* @param {Array} v
816-
* @param {number} k
817-
* @return {number}
818+
* @param {Array} v - The input array of values to interpolate between.
819+
* @param {number} k - The percentage of interpolation, between 0 and 1.
820+
* @return {number} The interpolated value
818821
*/
819822
catmullRomInterpolation: function (v, k) {
820823

@@ -830,7 +833,6 @@ Phaser.Math = {
830833
}
831834

832835
return this.catmullRom(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
833-
834836
}
835837
else
836838
{
@@ -880,14 +882,14 @@ Phaser.Math = {
880882
*/
881883
factorial : function( value ){
882884

883-
if(value === 0)
885+
if (value === 0)
884886
{
885887
return 1;
886888
}
887889

888890
var res = value;
889891

890-
while( --value )
892+
while(--value)
891893
{
892894
res *= value;
893895
}
@@ -897,7 +899,7 @@ Phaser.Math = {
897899
},
898900

899901
/**
900-
* Calculates a callmum rom value.
902+
* Calculates a catmum rom value.
901903
*
902904
* @method Phaser.Math#catmullRom
903905
* @protected

src/tween/Tween.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Phaser.Tween.prototype = {
177177
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
178178
*
179179
* @method Phaser.Tween#to
180-
* @param {object} properties - An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
180+
* @param {object} properties - An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
181181
* @param {number} [duration=1000] - Duration of this tween in ms.
182182
* @param {function|string} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden.
183183
* @param {boolean} [autoStart=false] - Set to `true` to allow this tween to start automatically. Otherwise call Tween.start().
@@ -496,11 +496,11 @@ Phaser.Tween.prototype = {
496496
* Sets the interpolation function the tween will use. By default it uses Phaser.Math.linearInterpolation.
497497
* Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation.
498498
* The interpolation function is only used if the target properties is an array.
499-
* If you have child tweens and pass -1 as the index value it sets the interpolation function across all of them.
499+
* If you have child tweens and pass -1 as the index value and it will set the interpolation function across all of them.
500500
*
501501
* @method Phaser.Tween#interpolation
502502
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
503-
* @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 easing function on all children.
503+
* @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.
504504
* @return {Phaser.Tween} This tween. Useful for method chaining.
505505
*/
506506
interpolation: function (interpolation, index) {

src/tween/TweenData.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ Phaser.TweenData = function (parent) {
7777
*/
7878
this.repeatDelay = 0;
7979

80+
/**
81+
* @property {boolean} interpolate - True if the Tween will use interpolation (i.e. is an Array to Array tween)
82+
* @default
83+
*/
84+
this.interpolate = false;
85+
8086
/**
8187
* @property {boolean} yoyo - True if the Tween is set to yoyo, otherwise false.
8288
* @default
@@ -117,6 +123,12 @@ Phaser.TweenData = function (parent) {
117123
*/
118124
this.interpolationFunction = Phaser.Math.linearInterpolation;
119125

126+
/**
127+
* @property {object} interpolationFunctionContext - The interpolation function context used for the Tween.
128+
* @default Phaser.Math
129+
*/
130+
this.interpolationFunctionContext = Phaser.Math;
131+
120132
/**
121133
* @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.
122134
* @default
@@ -273,7 +285,7 @@ Phaser.TweenData.prototype = {
273285
// Load the property from the parent object
274286
this.vStart[property] = this.parent.properties[property];
275287

276-
// Check if an Array was provided as property value (NEEDS TESTING)
288+
// Check if an Array was provided as property value
277289
if (Array.isArray(this.vEnd[property]))
278290
{
279291
if (this.vEnd[property].length === 0)
@@ -282,7 +294,7 @@ Phaser.TweenData.prototype = {
282294
}
283295

284296
// Create a local copy of the Array with the start value at the front
285-
this.vEnd[property] = [this.parent.properties[property]].concat(this.vEnd[property]);
297+
this.vEnd[property] = [this.vStart[property]].concat(this.vEnd[property]);
286298
}
287299

288300
if (typeof this.vEnd[property] !== 'undefined')
@@ -352,7 +364,7 @@ Phaser.TweenData.prototype = {
352364

353365
if (Array.isArray(end))
354366
{
355-
this.parent.target[property] = this.interpolationFunction(end, this.value);
367+
this.parent.target[property] = this.interpolationFunction.call(this.interpolationFunctionContext, end, this.value);
356368
}
357369
else
358370
{

0 commit comments

Comments
 (0)