Added class constructors, fixed Stripshader, added relative Tween example and updated Tween source.

This commit is contained in:
photonstorm
2013-12-30 16:54:00 +00:00
parent fdbdd81b7b
commit ce4cf531d4
59 changed files with 324 additions and 149 deletions
+76 -120
View File
@@ -112,14 +112,7 @@ Phaser.Tween = function (object, game) {
this._chainedTweens = [];
/**
* @property {function} _onStartCallback - An onStart callback.
* @private
* @default
*/
this._onStartCallback = null;
/**
* @property {boolean} _onStartCallbackFired - Private onStart flag.
* @property {boolean} _onStartCallbackFired - Private flag.
* @private
* @default
*/
@@ -131,14 +124,7 @@ Phaser.Tween = function (object, game) {
* @default null
*/
this._onUpdateCallback = null;
/**
* @property {function} _onCompleteCallback - An onComplete callback.
* @private
* @default null
*/
this._onCompleteCallback = null;
/**
* @property {number} _pausedTime - Private pause timer.
* @private
@@ -196,7 +182,7 @@ Phaser.Tween.prototype = {
* @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself when it completes.
* @return {Phaser.Tween} This Tween object.
*/
to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) {
to: function (properties, duration, ease, autoStart, delay, repeat, yoyo) {
duration = duration || 1000;
ease = ease || null;
@@ -236,9 +222,12 @@ Phaser.Tween.prototype = {
self._yoyo = yoyo;
if (autoStart) {
if (autoStart)
{
return this.start();
} else {
}
else
{
return this;
}
@@ -252,7 +241,8 @@ Phaser.Tween.prototype = {
*/
start: function () {
if (this.game === null || this._object === null) {
if (this.game === null || this._object === null)
{
return;
}
@@ -264,29 +254,28 @@ Phaser.Tween.prototype = {
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 ) {
if ( this._valuesEnd[ property ].length === 0 ) {
if (this._valuesEnd[property] instanceof Array)
{
if (this._valuesEnd[property].length === 0)
{
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 ] );
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;
}
@@ -317,7 +306,7 @@ Phaser.Tween.prototype = {
* @param {number} amount - The amount of the delay in ms.
* @return {Phaser.Tween} Itself.
*/
delay: function ( amount ) {
delay: function (amount) {
this._delayTime = amount;
return this;
@@ -331,7 +320,7 @@ Phaser.Tween.prototype = {
* @param {number} times - How many times to repeat.
* @return {Phaser.Tween} Itself.
*/
repeat: function ( times ) {
repeat: function (times) {
this._repeat = times;
return this;
@@ -346,7 +335,7 @@ Phaser.Tween.prototype = {
* @param {boolean} yoyo - Set to true to yoyo this tween.
* @return {Phaser.Tween} Itself.
*/
yoyo: function( yoyo ) {
yoyo: function(yoyo) {
this._yoyo = yoyo;
return this;
@@ -360,7 +349,7 @@ Phaser.Tween.prototype = {
* @param {function} easing - The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* @return {Phaser.Tween} Itself.
*/
easing: function ( easing ) {
easing: function (easing) {
this._easingFunction = easing;
return this;
@@ -369,12 +358,13 @@ Phaser.Tween.prototype = {
/**
* Set interpolation function the tween will use, by default it uses Phaser.Math.linearInterpolation.
* Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation.
*
* @method Phaser.Tween#interpolation
* @param {function} interpolation - The interpolation function to use (Phaser.Math.linearInterpolation by default)
* @return {Phaser.Tween} Itself.
*/
interpolation: function ( interpolation ) {
interpolation: function (interpolation) {
this._interpolationFunction = interpolation;
return this;
@@ -414,20 +404,6 @@ Phaser.Tween.prototype = {
},
/**
* 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;
},
/**
* Sets a callback to be fired each time this tween updates. Note: callback will be called in the context of the global scope.
*
@@ -435,35 +411,23 @@ Phaser.Tween.prototype = {
* @param {function} callback - The callback to invoke each time this tween is updated.
* @return {Phaser.Tween} Itself.
*/
onUpdateCallback: function ( callback ) {
onUpdateCallback: function (callback) {
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 ) {
this._onCompleteCallback = callback;
return this;
},
/**
* Pauses the tween.
*
* @method Phaser.Tween#pause
*/
pause: function () {
this._paused = true;
this._pausedTime = this.game.time.now;
},
/**
@@ -472,8 +436,10 @@ Phaser.Tween.prototype = {
* @method Phaser.Tween#resume
*/
resume: function () {
this._paused = false;
this._startTime += (this.game.time.now - this._pausedTime);
},
/**
@@ -483,7 +449,7 @@ Phaser.Tween.prototype = {
* @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 ) {
update: function (time) {
if (this.pendingDelete)
{
@@ -505,77 +471,70 @@ Phaser.Tween.prototype = {
if (this._onStartCallbackFired === false)
{
this.onStart.dispatch(this._object);
if (this._onStartCallback !== null )
{
this._onStartCallback.call( this._object );
}
this._onStartCallbackFired = true;
}
var elapsed = ( time - this._startTime ) / this._duration;
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 ) {
var start = this._valuesStart[ property ] || 0;
var end = this._valuesEnd[ property ];
if ( end instanceof Array ) {
this._object[ property ] = this._interpolationFunction( end, value );
} else {
for (property in this._valuesEnd)
{
var start = this._valuesStart[property] || 0;
var end = this._valuesEnd[property];
if (end instanceof Array)
{
this._object[property] = this._interpolationFunction(end, value);
}
else
{
// Parses relative end values with start as base (e.g.: +10, -3)
if ( typeof(end) === "string" ) {
if (typeof(end) === 'string')
{
end = start + parseFloat(end, 10);
}
// protect against non numeric properties.
if ( typeof(end) === "number" ) {
this._object[ property ] = start + ( end - start ) * value;
if (typeof(end) === 'number')
{
this._object[property] = start + ( end - start ) * value;
}
}
}
if ( this._onUpdateCallback !== null ) {
this._onUpdateCallback.call( this._object, value );
if (this._onUpdateCallback !== null)
{
this._onUpdateCallback.call(this._object, value);
}
if ( elapsed == 1 ) {
if ( this._repeat > 0 ) {
if ( isFinite( this._repeat ) ) {
if (elapsed == 1)
{
if (this._repeat > 0)
{
if (isFinite(this._repeat))
{
this._repeat--;
}
// reassign starting values, restart by making startTime = now
for ( property in this._valuesStartRepeat ) {
if ( typeof( this._valuesEnd[ property ] ) === "string" )
for (property in this._valuesStartRepeat)
{
if (typeof(this._valuesEnd[property]) === 'string')
{
this._valuesStartRepeat[ property ] = this._valuesStartRepeat[ property ] + parseFloat(this._valuesEnd[ property ], 10);
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;
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._valuesStart[property] = this._valuesStartRepeat[property];
}
this._startTime = time + this._delayTime;
@@ -584,23 +543,18 @@ Phaser.Tween.prototype = {
return true;
} else {
}
else
{
this.isRunning = false;
this.onComplete.dispatch(this._object);
if ( this._onCompleteCallback !== null ) {
this._onCompleteCallback.call( this._object );
}
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
this._chainedTweens[ i ].start( time );
for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++)
{
this._chainedTweens[i].start(time);
}
return false;
}
}
@@ -610,3 +564,5 @@ Phaser.Tween.prototype = {
}
};
Phaser.Tween.prototype.constructor = Phaser.Tween;
+3 -1
View File
@@ -202,4 +202,6 @@ Phaser.TweenManager.prototype = {
}
};
};
Phaser.TweenManager.prototype.constructor = Phaser.TweenManager;