The entire Phaser library has been updated to match the new JSHint configuration.

This commit is contained in:
photonstorm
2013-11-25 04:40:04 +00:00
parent 13a2cc2feb
commit 299115ca5d
74 changed files with 4992 additions and 4977 deletions
+375 -373
View File
@@ -1,3 +1,5 @@
/* jshint curly: false */
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
@@ -16,546 +18,546 @@ Phaser.Easing = {
*
* @class Phaser.Easing.Linear
*/
Linear: {
Linear: {
/**
* Ease-in.
*
* @method Phaser.Easing.Linear#In
* @param {number} k - The value to be tweened.
* @returns {number} k^2.
*/
None: function ( k ) {
/**
* Ease-in.
*
* @method Phaser.Easing.Linear#In
* @param {number} k - The value to be tweened.
* @returns {number} k^2.
*/
None: function ( k ) {
return k;
return k;
}
}
},
},
/**
* Quadratic easing.
*
* @class Phaser.Easing.Quadratic
*/
Quadratic: {
Quadratic: {
/**
* Ease-in.
*
* @method Phaser.Easing.Quadratic#In
* @param {number} k - The value to be tweened.
* @returns {number} k^2.
*/
In: function ( k ) {
/**
* Ease-in.
*
* @method Phaser.Easing.Quadratic#In
* @param {number} k - The value to be tweened.
* @returns {number} k^2.
*/
In: function ( k ) {
return k * k;
return k * k;
},
},
/**
* Ease-out.
*
* @method Phaser.Easing.Quadratic#Out
* @param {number} k - The value to be tweened.
* @returns {number} k* (2-k).
*/
Out: function ( k ) {
/**
* Ease-out.
*
* @method Phaser.Easing.Quadratic#Out
* @param {number} k - The value to be tweened.
* @returns {number} k* (2-k).
*/
Out: function ( k ) {
return k * ( 2 - k );
return k * ( 2 - k );
},
},
/**
* Ease-in/out.
*
* @method Phaser.Easing.Quadratic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Ease-in/out.
*
* @method Phaser.Easing.Quadratic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
return - 0.5 * ( --k * ( k - 2 ) - 1 );
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
return - 0.5 * ( --k * ( k - 2 ) - 1 );
}
}
},
},
/**
* Cubic easing.
*
* @class Phaser.Easing.Cubic
*/
Cubic: {
Cubic: {
/**
* Cubic ease-in.
*
* @method Phaser.Easing.Cubic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Cubic ease-in.
*
* @method Phaser.Easing.Cubic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return k * k * k;
return k * k * k;
},
},
/**
* Cubic ease-out.
*
* @method Phaser.Easing.Cubic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Cubic ease-out.
*
* @method Phaser.Easing.Cubic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return --k * k * k + 1;
return --k * k * k + 1;
},
},
/**
* Cubic ease-in/out.
*
* @method Phaser.Easing.Cubic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Cubic ease-in/out.
*
* @method Phaser.Easing.Cubic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
return 0.5 * ( ( k -= 2 ) * k * k + 2 );
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
return 0.5 * ( ( k -= 2 ) * k * k + 2 );
}
}
},
},
/**
* Quartic easing.
*
* @class Phaser.Easing.Quartic
*/
Quartic: {
Quartic: {
/**
* Quartic ease-in.
*
* @method Phaser.Easing.Quartic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Quartic ease-in.
*
* @method Phaser.Easing.Quartic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return k * k * k * k;
return k * k * k * k;
},
},
/**
* Quartic ease-out.
*
* @method Phaser.Easing.Quartic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Quartic ease-out.
*
* @method Phaser.Easing.Quartic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return 1 - ( --k * k * k * k );
return 1 - ( --k * k * k * k );
},
},
/**
* Quartic ease-in/out.
*
* @method Phaser.Easing.Quartic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Quartic ease-in/out.
*
* @method Phaser.Easing.Quartic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 );
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 );
}
}
},
},
/**
* Quintic easing.
*
* @class Phaser.Easing.Quintic
*/
Quintic: {
Quintic: {
/**
* Quintic ease-in.
*
* @method Phaser.Easing.Quintic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Quintic ease-in.
*
* @method Phaser.Easing.Quintic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return k * k * k * k * k;
return k * k * k * k * k;
},
},
/**
* Quintic ease-out.
*
* @method Phaser.Easing.Quintic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Quintic ease-out.
*
* @method Phaser.Easing.Quintic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return --k * k * k * k * k + 1;
return --k * k * k * k * k + 1;
},
},
/**
* Quintic ease-in/out.
*
* @method Phaser.Easing.Quintic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Quintic ease-in/out.
*
* @method Phaser.Easing.Quintic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
}
}
},
},
/**
* Sinusoidal easing.
*
* @class Phaser.Easing.Sinusoidal
*/
Sinusoidal: {
Sinusoidal: {
/**
* Sinusoidal ease-in.
*
* @method Phaser.Easing.Sinusoidal#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Sinusoidal ease-in.
*
* @method Phaser.Easing.Sinusoidal#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return 1 - Math.cos( k * Math.PI / 2 );
return 1 - Math.cos( k * Math.PI / 2 );
},
},
/**
* Sinusoidal ease-out.
*
* @method Phaser.Easing.Sinusoidal#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Sinusoidal ease-out.
*
* @method Phaser.Easing.Sinusoidal#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return Math.sin( k * Math.PI / 2 );
return Math.sin( k * Math.PI / 2 );
},
},
/**
* Sinusoidal ease-in/out.
*
* @method Phaser.Easing.Sinusoidal#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Sinusoidal ease-in/out.
*
* @method Phaser.Easing.Sinusoidal#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
}
}
},
},
/**
* Exponential easing.
*
* @class Phaser.Easing.Exponential
*/
Exponential: {
Exponential: {
/**
* Exponential ease-in.
*
* @method Phaser.Easing.Exponential#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Exponential ease-in.
*
* @method Phaser.Easing.Exponential#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
},
},
/**
* Exponential ease-out.
*
* @method Phaser.Easing.Exponential#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Exponential ease-out.
*
* @method Phaser.Easing.Exponential#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
},
},
/**
* Exponential ease-in/out.
*
* @method Phaser.Easing.Exponential#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Exponential ease-in/out.
*
* @method Phaser.Easing.Exponential#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 1024, k - 1 );
return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 );
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 1024, k - 1 );
return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 );
}
}
},
},
/**
* Circular easing.
*
* @class Phaser.Easing.Circular
*/
Circular: {
Circular: {
/**
* Circular ease-in.
*
* @method Phaser.Easing.Circular#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return 1 - Math.sqrt( 1 - k * k );
},
/**
* Circular ease-out.
*
* @method Phaser.Easing.Circular#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return Math.sqrt( 1 - ( --k * k ) );
},
/**
* Circular ease-in/out.
/**
* Circular ease-in.
*
* @method Phaser.Easing.Circular#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
* @method Phaser.Easing.Circular#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
In: function ( k ) {
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1);
return 1 - Math.sqrt( 1 - k * k );
}
},
},
/**
* Circular ease-out.
*
* @method Phaser.Easing.Circular#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
return Math.sqrt( 1 - ( --k * k ) );
},
/**
* Circular ease-in/out.
*
* @method Phaser.Easing.Circular#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1);
}
},
/**
* Elastic easing.
*
* @class Phaser.Easing.Elastic
*/
Elastic: {
Elastic: {
/**
* Elastic ease-in.
*
* @method Phaser.Easing.Elastic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Elastic ease-in.
*
* @method Phaser.Easing.Elastic#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
},
},
/**
* Elastic ease-out.
*
* @method Phaser.Easing.Elastic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Elastic ease-out.
*
* @method Phaser.Easing.Elastic#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
},
},
/**
* Elastic ease-in/out.
*
* @method Phaser.Easing.Elastic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Elastic ease-in/out.
*
* @method Phaser.Easing.Elastic#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
var s, a = 0.1, p = 0.4;
if ( k === 0 ) return 0;
if ( k === 1 ) return 1;
if ( !a || a < 1 ) { a = 1; s = p / 4; }
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
}
}
},
},
/**
* Back easing.
*
* @class Phaser.Easing.Back
*/
Back: {
Back: {
/**
* Back ease-in.
*
* @method Phaser.Easing.Back#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Back ease-in.
*
* @method Phaser.Easing.Back#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
var s = 1.70158;
return k * k * ( ( s + 1 ) * k - s );
var s = 1.70158;
return k * k * ( ( s + 1 ) * k - s );
},
},
/**
* Back ease-out.
*
* @method Phaser.Easing.Back#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Back ease-out.
*
* @method Phaser.Easing.Back#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
var s = 1.70158;
return --k * k * ( ( s + 1 ) * k + s ) + 1;
var s = 1.70158;
return --k * k * ( ( s + 1 ) * k + s ) + 1;
},
},
/**
* Back ease-in/out.
*
* @method Phaser.Easing.Back#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Back ease-in/out.
*
* @method Phaser.Easing.Back#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
var s = 1.70158 * 1.525;
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
var s = 1.70158 * 1.525;
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
}
}
},
},
/**
* Bounce easing.
*
* @class Phaser.Easing.Bounce
*/
Bounce: {
Bounce: {
/**
* Bounce ease-in.
*
* @method Phaser.Easing.Bounce#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
/**
* Bounce ease-in.
*
* @method Phaser.Easing.Bounce#In
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
In: function ( k ) {
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
},
},
/**
* Bounce ease-out.
*
* @method Phaser.Easing.Bounce#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
/**
* Bounce ease-out.
*
* @method Phaser.Easing.Bounce#Out
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
Out: function ( k ) {
if ( k < ( 1 / 2.75 ) ) {
if ( k < ( 1 / 2.75 ) ) {
return 7.5625 * k * k;
return 7.5625 * k * k;
} else if ( k < ( 2 / 2.75 ) ) {
} else if ( k < ( 2 / 2.75 ) ) {
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
} else if ( k < ( 2.5 / 2.75 ) ) {
} else if ( k < ( 2.5 / 2.75 ) ) {
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
} else {
} else {
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
}
}
},
},
/**
* Bounce ease-in/out.
*
* @method Phaser.Easing.Bounce#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
/**
* Bounce ease-in/out.
*
* @method Phaser.Easing.Bounce#InOut
* @param {number} k - The value to be tweened.
* @returns {number} The tweened value.
*/
InOut: function ( k ) {
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
return Phaser.Easing.Bounce.Out( k * 2 - 1 ) * 0.5 + 0.5;
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
return Phaser.Easing.Bounce.Out( k * 2 - 1 ) * 0.5 + 0.5;
}
}
}
}
};
+282 -283
View File
@@ -20,7 +20,7 @@ Phaser.Tween = function (object, game) {
* @property {object} _object
* @private
*/
this._object = object;
this._object = object;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
@@ -154,7 +154,7 @@ Phaser.Tween = function (object, game) {
// Set all starting values present on the target object
for ( var field in object ) {
this._valuesStart[ field ] = parseFloat(object[field], 10);
this._valuesStart[ field ] = parseFloat(object[field], 10);
}
/**
@@ -177,45 +177,45 @@ Phaser.Tween = function (object, game) {
Phaser.Tween.prototype = {
/**
* Configure the Tween
*
* @method Phaser.Tween#to
* @param {object} properties - Properties you want to tween.
* @param {number} duration - Duration of this tween.
* @param {function} ease - Easing function.
* @param {boolean} autoStart - Whether this tween will start automatically or not.
* @param {number} delay - Delay before this tween will start, defaults to 0 (no delay).
* @param {boolean} repeat - Should the tween automatically restart once complete? (ignores any chained tweens).
* @param {Phaser.Tween} yoyo - Description.
* @return {Phaser.Tween} Itself.
*/
to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) {
/**
* Configure the Tween
*
* @method Phaser.Tween#to
* @param {object} properties - Properties you want to tween.
* @param {number} duration - Duration of this tween.
* @param {function} ease - Easing function.
* @param {boolean} autoStart - Whether this tween will start automatically or not.
* @param {number} delay - Delay before this tween will start, defaults to 0 (no delay).
* @param {boolean} repeat - Should the tween automatically restart once complete? (ignores any chained tweens).
* @param {Phaser.Tween} yoyo - Description.
* @return {Phaser.Tween} Itself.
*/
to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) {
duration = duration || 1000;
ease = ease || null;
autoStart = autoStart || false;
delay = delay || 0;
repeat = repeat || 0;
yoyo = yoyo || false;
duration = duration || 1000;
ease = ease || null;
autoStart = autoStart || false;
delay = delay || 0;
repeat = repeat || 0;
yoyo = yoyo || false;
var self;
if (this._parent)
{
self = this._manager.create(this._object);
this._lastChild.chain(self);
this._lastChild = self;
}
else
{
self = this;
this._parent = this;
this._lastChild = this;
}
var self;
if (this._parent)
{
self = this._manager.create(this._object);
this._lastChild.chain(self);
this._lastChild = self;
}
else
{
self = this;
this._parent = this;
this._lastChild = this;
}
self._repeat = repeat;
self._repeat = repeat;
self._duration = duration;
self._valuesEnd = properties;
self._valuesEnd = properties;
if (ease !== null)
{
@@ -235,256 +235,255 @@ Phaser.Tween.prototype = {
return this;
}
},
},
/**
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
*
* @method Phaser.Tween#start
* @param {number} time - Description.
* @return {Phaser.Tween} Itself.
*/
start: function ( time ) {
/**
* Starts the tween running. Can also be called by the autoStart parameter of Tween.to.
*
* @method Phaser.Tween#start
* @return {Phaser.Tween} Itself.
*/
start: function () {
if (this.game === null || this._object === null) {
return;
}
this._manager.add(this);
this._manager.add(this);
this.onStart.dispatch(this._object);
this.onStart.dispatch(this._object);
this.isRunning = true;
this._onStartCallbackFired = false;
this._onStartCallbackFired = false;
this._startTime = this.game.time.now + this._delayTime;
for ( var property in this._valuesEnd ) {
for ( var property in this._valuesEnd ) {
// check if an Array was provided as property value
if ( this._valuesEnd[ property ] instanceof Array ) {
// check if an Array was provided as property value
if ( this._valuesEnd[ property ] instanceof Array ) {
if ( this._valuesEnd[ property ].length === 0 ) {
if ( this._valuesEnd[ property ].length === 0 ) {
continue;
continue;
}
}
// create a local copy of the Array with the start value at the front
this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
// create a local copy of the Array with the start value at the front
this._valuesEnd[ property ] = [ this._object[ property ] ].concat( this._valuesEnd[ property ] );
}
}
this._valuesStart[ property ] = this._object[ property ];
this._valuesStart[ property ] = this._object[ property ];
if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
}
if ( ( this._valuesStart[ property ] instanceof Array ) === false ) {
this._valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
}
this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
this._valuesStartRepeat[ property ] = this._valuesStart[ property ] || 0;
}
}
return this;
return this;
},
},
/**
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
*
* @method Phaser.Tween#stop
* @return {Phaser.Tween} Itself.
*/
stop: function () {
/**
* Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.
*
* @method Phaser.Tween#stop
* @return {Phaser.Tween} Itself.
*/
stop: function () {
this.isRunning = false;
this._manager.remove(this);
this._manager.remove(this);
return this;
return this;
},
},
/**
* Sets a delay time before this tween will start.
*
* @method Phaser.Tween#delay
* @param {number} amount - The amount of the delay in ms.
* @return {Phaser.Tween} Itself.
*/
delay: function ( amount ) {
/**
* Sets a delay time before this tween will start.
*
* @method Phaser.Tween#delay
* @param {number} amount - The amount of the delay in ms.
* @return {Phaser.Tween} Itself.
*/
delay: function ( amount ) {
this._delayTime = amount;
return this;
this._delayTime = amount;
return this;
},
},
/**
* Sets the number of times this tween will repeat.
*
* @method Phaser.Tween#repeat
* @param {number} times - How many times to repeat.
* @return {Phaser.Tween} Itself.
*/
repeat: function ( times ) {
/**
* Sets the number of times this tween will repeat.
*
* @method Phaser.Tween#repeat
* @param {number} times - How many times to repeat.
* @return {Phaser.Tween} Itself.
*/
repeat: function ( times ) {
this._repeat = times;
return this;
this._repeat = times;
return this;
},
},
/**
* A tween that has yoyo set to true will run through from start to finish, then reverse from finish to start.
* Used in combination with repeat you can create endless loops.
*
* @method Phaser.Tween#yoyo
* @param {boolean} yoyo - Set to true to yoyo this tween.
* @return {Phaser.Tween} Itself.
*/
yoyo: function( yoyo ) {
/**
* A tween that has yoyo set to true will run through from start to finish, then reverse from finish to start.
* Used in combination with repeat you can create endless loops.
*
* @method Phaser.Tween#yoyo
* @param {boolean} yoyo - Set to true to yoyo this tween.
* @return {Phaser.Tween} Itself.
*/
yoyo: function( yoyo ) {
this._yoyo = yoyo;
return this;
this._yoyo = yoyo;
return this;
},
},
/**
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
*
* @method Phaser.Tween#easing
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* @return {Phaser.Tween} Itself.
*/
easing: function ( easing ) {
/**
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
*
* @method Phaser.Tween#easing
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* @return {Phaser.Tween} Itself.
*/
easing: function ( easing ) {
this._easingFunction = easing;
return this;
this._easingFunction = easing;
return this;
},
},
/**
* Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation.
*
* @method Phaser.Tween#interpolation
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
* @return {Phaser.Tween} Itself.
*/
interpolation: function ( interpolation ) {
/**
* Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation.
*
* @method Phaser.Tween#interpolation
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
* @return {Phaser.Tween} Itself.
*/
interpolation: function ( interpolation ) {
this._interpolationFunction = interpolation;
return this;
this._interpolationFunction = interpolation;
return this;
},
},
/**
* You can chain tweens together by passing a reference to the chain function. This enables one tween to call another on completion.
* You can pass as many tweens as you like to this function, they will each be chained in sequence.
*
* @method Phaser.Tween#chain
* @return {Phaser.Tween} Itself.
*/
chain: function () {
/**
* You can chain tweens together by passing a reference to the chain function. This enables one tween to call another on completion.
* You can pass as many tweens as you like to this function, they will each be chained in sequence.
*
* @method Phaser.Tween#chain
* @return {Phaser.Tween} Itself.
*/
chain: function () {
this._chainedTweens = arguments;
return this;
this._chainedTweens = arguments;
return this;
},
},
/**
* 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();
* @method Phaser.Tween#loop
* @return {Phaser.Tween} Itself.
*/
loop: function() {
/**
* 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();
* @method Phaser.Tween#loop
* @return {Phaser.Tween} Itself.
*/
loop: function() {
this._lastChild.chain(this);
return this;
this._lastChild.chain(this);
return this;
},
},
/**
* Sets a callback to be fired when the tween starts. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onStartCallback
* @param {function} callback - The callback to invoke on start.
* @return {Phaser.Tween} Itself.
*/
onStartCallback: function ( callback ) {
/**
* Sets a callback to be fired when the tween starts. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onStartCallback
* @param {function} callback - The callback to invoke on start.
* @return {Phaser.Tween} Itself.
*/
onStartCallback: function ( callback ) {
this._onStartCallback = callback;
return this;
this._onStartCallback = callback;
return this;
},
},
/**
* Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onUpdateCallback
* @param {function} callback - The callback to invoke each time this tween is updated.
* @return {Phaser.Tween} Itself.
*/
onUpdateCallback: function ( callback ) {
/**
* Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onUpdateCallback
* @param {function} callback - The callback to invoke each time this tween is updated.
* @return {Phaser.Tween} Itself.
*/
onUpdateCallback: function ( callback ) {
this._onUpdateCallback = callback;
return this;
this._onUpdateCallback = callback;
return this;
},
},
/**
* Sets a callback to be fired when the tween completes. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onCompleteCallback
* @param {function} callback - The callback to invoke on completion.
* @return {Phaser.Tween} Itself.
*/
onCompleteCallback: function ( callback ) {
/**
* Sets a callback to be fired when the tween completes. Note: callback will be called in the context of the global scope.
*
* @method Phaser.Tween#onCompleteCallback
* @param {function} callback - The callback to invoke on completion.
* @return {Phaser.Tween} Itself.
*/
onCompleteCallback: function ( callback ) {
this._onCompleteCallback = callback;
return this;
this._onCompleteCallback = callback;
return this;
},
},
/**
* Pauses the tween.
*
* @method Phaser.Tween#pause
*/
/**
* Pauses the tween.
*
* @method Phaser.Tween#pause
*/
pause: function () {
this._paused = true;
this._pausedTime = this.game.time.now;
},
/**
* Resumes a paused tween.
*
* @method Phaser.Tween#resume
*/
/**
* Resumes a paused tween.
*
* @method Phaser.Tween#resume
*/
resume: function () {
this._paused = false;
this._startTime += (this.game.time.now - this._pausedTime);
},
/**
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
*
* @method Phaser.Tween#update
* @param {number} time - A timestamp passed in by the TweenManager.
* @return {boolean} false if the tween has completed and should be deleted from the manager, otherwise true (still active).
*/
update: function ( time ) {
/**
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
*
* @method Phaser.Tween#update
* @param {number} time - A timestamp passed in by the TweenManager.
* @return {boolean} false if the tween has completed and should be deleted from the manager, otherwise true (still active).
*/
update: function ( time ) {
if (this.pendingDelete)
{
return false;
}
if (this.pendingDelete)
{
return false;
}
if (this._paused || time < this._startTime) {
@@ -492,120 +491,120 @@ Phaser.Tween.prototype = {
}
var property;
var property;
if ( time < this._startTime ) {
if ( time < this._startTime ) {
return true;
return true;
}
}
if ( this._onStartCallbackFired === false ) {
if ( this._onStartCallbackFired === false ) {
if ( this._onStartCallback !== null ) {
if ( this._onStartCallback !== null ) {
this._onStartCallback.call( this._object );
this._onStartCallback.call( this._object );
}
}
this._onStartCallbackFired = true;
this._onStartCallbackFired = true;
}
}
var elapsed = ( time - this._startTime ) / this._duration;
elapsed = elapsed > 1 ? 1 : elapsed;
var elapsed = ( time - this._startTime ) / this._duration;
elapsed = elapsed > 1 ? 1 : elapsed;
var value = this._easingFunction( elapsed );
var value = this._easingFunction( elapsed );
for ( property in this._valuesEnd ) {
for ( property in this._valuesEnd ) {
var start = this._valuesStart[ property ] || 0;
var end = this._valuesEnd[ property ];
var start = this._valuesStart[ property ] || 0;
var end = this._valuesEnd[ property ];
if ( end instanceof Array ) {
if ( end instanceof Array ) {
this._object[ property ] = this._interpolationFunction( end, value );
this._object[ property ] = this._interpolationFunction( end, value );
} else {
} else {
// Parses relative end values with start as base (e.g.: +10, -3)
if ( typeof(end) === "string" ) {
end = start + parseFloat(end, 10);
}
if ( typeof(end) === "string" ) {
end = start + parseFloat(end, 10);
}
// protect against non numeric properties.
// protect against non numeric properties.
if ( typeof(end) === "number" ) {
this._object[ property ] = start + ( end - start ) * value;
}
this._object[ property ] = start + ( end - start ) * value;
}
}
}
}
}
if ( this._onUpdateCallback !== null ) {
if ( this._onUpdateCallback !== null ) {
this._onUpdateCallback.call( this._object, value );
this._onUpdateCallback.call( this._object, value );
}
}
if ( elapsed == 1 ) {
if ( elapsed == 1 ) {
if ( this._repeat > 0 ) {
if ( this._repeat > 0 ) {
if ( isFinite( this._repeat ) ) {
this._repeat--;
}
if ( isFinite( this._repeat ) ) {
this._repeat--;
}
// reassign starting values, restart by making startTime = now
for ( property in this._valuesStartRepeat ) {
// reassign starting values, restart by making startTime = now
for ( property in this._valuesStartRepeat ) {
if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10);
}
if ( typeof( this._valuesEnd[ property ] ) === "string" ) {
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10);
}
if (this._yoyo) {
var tmp = this._valuesStartRepeat[ property ];
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
this._valuesEnd[ property ] = tmp;
this._reversed = !this._reversed;
}
this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
if (this._yoyo) {
var tmp = this._valuesStartRepeat[ property ];
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
this._valuesEnd[ property ] = tmp;
this._reversed = !this._reversed;
}
this._valuesStart[ property ] = this._valuesStartRepeat[ property ];
}
}
this._startTime = time + this._delayTime;
this._startTime = time + this._delayTime;
this.onComplete.dispatch(this._object);
this.onComplete.dispatch(this._object);
if ( this._onCompleteCallback !== null ) {
this._onCompleteCallback.call( this._object );
}
if ( this._onCompleteCallback !== null ) {
this._onCompleteCallback.call( this._object );
}
return true;
return true;
} else {
} else {
this.isRunning = false;
this.onComplete.dispatch(this._object);
this.isRunning = false;
this.onComplete.dispatch(this._object);
if ( this._onCompleteCallback !== null ) {
this._onCompleteCallback.call( this._object );
}
if ( this._onCompleteCallback !== null ) {
this._onCompleteCallback.call( this._object );
}
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
this._chainedTweens[ i ].start( time );
this._chainedTweens[ i ].start( time );
}
}
return false;
return false;
}
}
}
}
return true;
return true;
}
}
};
+147 -144
View File
@@ -22,180 +22,183 @@
*/
Phaser.TweenManager = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {array} _tweens - Description.
* @private
*/
this._tweens = [];
/**
* @property {array} _add - Description.
* @private
*/
this._add = [];
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {array} _tweens - Description.
* @private
*/
this._tweens = [];
/**
* @property {array} _add - Description.
* @private
*/
this._add = [];
this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this);
this.game.onPause.add(this.pauseAll, this);
this.game.onResume.add(this.resumeAll, this);
};
Phaser.TweenManager.prototype = {
/**
* Version number of this library.
* @property {string} REVISION
* @default
*/
REVISION: '11dev',
/**
* Version number of this library.
* @property {string} REVISION
* @default
*/
REVISION: '11dev',
/**
* Get all the tween objects in an array.
* @method Phaser.TweenManager#getAll
* @returns {Phaser.Tween[]} Array with all tween objects.
*/
getAll: function () {
/**
* Get all the tween objects in an array.
* @method Phaser.TweenManager#getAll
* @returns {Phaser.Tween[]} Array with all tween objects.
*/
getAll: function () {
return this._tweens;
return this._tweens;
},
},
/**
* Remove all tween objects.
* @method Phaser.TweenManager#removeAll
*/
removeAll: function () {
/**
* Remove all tween objects.
* @method Phaser.TweenManager#removeAll
*/
removeAll: function () {
this._tweens = [];
this._tweens = [];
},
},
/**
* Add a new tween into the TweenManager.
*
* @method Phaser.TweenManager#add
* @param {Phaser.Tween} tween - The tween object you want to add.
* @returns {Phaser.Tween} The tween object you added to the manager.
*/
add: function ( tween ) {
/**
* Add a new tween into the TweenManager.
*
* @method Phaser.TweenManager#add
* @param {Phaser.Tween} tween - The tween object you want to add.
* @returns {Phaser.Tween} The tween object you added to the manager.
*/
add: function ( tween ) {
this._add.push( tween );
this._add.push( tween );
},
},
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @method Phaser.TweenManager#create
* @param {Object} object - Object the tween will be run on.
* @returns {Phaser.Tween} The newly created tween object.
*/
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @method Phaser.TweenManager#create
* @param {Object} object - Object the tween will be run on.
* @returns {Phaser.Tween} The newly created tween object.
*/
create: function (object) {
return new Phaser.Tween(object, this.game);
},
/**
* Remove a tween from this manager.
*
* @method Phaser.TweenManager#remove
* @param {Phaser.Tween} tween - The tween object you want to remove.
*/
remove: function ( tween ) {
/**
* Remove a tween from this manager.
*
* @method Phaser.TweenManager#remove
* @param {Phaser.Tween} tween - The tween object you want to remove.
*/
remove: function ( tween ) {
var i = this._tweens.indexOf( tween );
var i = this._tweens.indexOf( tween );
if ( i !== -1 ) {
if ( i !== -1 ) {
this._tweens[i].pendingDelete = true;
this._tweens[i].pendingDelete = true;
}
},
/**
* Update all the tween objects you added to this manager.
*
* @method Phaser.TweenManager#update
* @returns {boolean} Return false if there's no tween to update, otherwise return true.
*/
update: function () {
if ( this._tweens.length === 0 && this._add.length === 0 ) return false;
var i = 0;
var numTweens = this._tweens.length;
while ( i < numTweens ) {
if ( this._tweens[ i ].update( this.game.time.now ) ) {
i++;
} else {
this._tweens.splice( i, 1 );
numTweens--;
}
}
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
if (this._add.length > 0)
{
this._tweens = this._tweens.concat(this._add);
this._add.length = 0;
}
return true;
},
/**
* Checks to see if a particular Sprite is currently being tweened.
*
* @method Phaser.TweenManager#isTweening
* @param {object} object - The object to check for tweens against.
* @returns {boolean} Returns true if the object is currently being tweened, false if not.
*/
isTweening: function(object) {
return this._tweens.some(function(tween) {
return tween._object === object;
});
},
/**
* Pauses all currently running tweens.
*
* @method Phaser.TweenManager#update
*/
pauseAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].pause();
};
}
},
/**
* Pauses all currently paused tweens.
*
* @method Phaser.TweenManager#resumeAll
*/
resumeAll: function () {
/**
* Update all the tween objects you added to this manager.
*
* @method Phaser.TweenManager#update
* @returns {boolean} Return false if there's no tween to update, otherwise return true.
*/
update: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].resume();
};
if ( this._tweens.length === 0 && this._add.length === 0 )
{
return false;
}
var i = 0;
var numTweens = this._tweens.length;
while ( i < numTweens ) {
if ( this._tweens[ i ].update( this.game.time.now ) ) {
i++;
} else {
this._tweens.splice( i, 1 );
numTweens--;
}
}
// If there are any new tweens to be added, do so now - otherwise they can be spliced out of the array before ever running
if (this._add.length > 0)
{
this._tweens = this._tweens.concat(this._add);
this._add.length = 0;
}
return true;
},
/**
* Checks to see if a particular Sprite is currently being tweened.
*
* @method Phaser.TweenManager#isTweening
* @param {object} object - The object to check for tweens against.
* @returns {boolean} Returns true if the object is currently being tweened, false if not.
*/
isTweening: function(object) {
return this._tweens.some(function(tween) {
return tween._object === object;
});
},
/**
* Pauses all currently running tweens.
*
* @method Phaser.TweenManager#update
*/
pauseAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].pause();
}
},
/**
* Pauses all currently paused tweens.
*
* @method Phaser.TweenManager#resumeAll
*/
resumeAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].resume();
}
}