Adding docs.

This commit is contained in:
Richard Davey
2013-10-01 15:01:46 +01:00
parent fa15f8015d
commit 305b12d76b
64 changed files with 6268 additions and 2682 deletions
+316
View File
@@ -1,7 +1,33 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Easing
*/
/**
* A collection of easing methods defining ease-in ease-out curves.
*
* @class Phaser.Easing
*/
Phaser.Easing = {
/**
* Linear easing.
*
* @namespace Linear
*/
Linear: {
/**
* Ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Linear
* @returns {number} k^2.
*/
None: function ( k ) {
return k;
@@ -10,20 +36,49 @@ Phaser.Easing = {
},
/**
* Quadratic easing.
*
* @namespace Quadratic
*/
Quadratic: {
/**
* Ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Quadratic
* @returns {number} k^2.
*/
In: function ( k ) {
return k * k;
},
/**
* Ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Quadratic
* @returns {number} k* (2-k).
*/
Out: function ( k ) {
return k * ( 2 - k );
},
/**
* Ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Quadratic
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
@@ -33,20 +88,49 @@ Phaser.Easing = {
},
/**
* Cubic easing.
*
* @namespace Cubic
*/
Cubic: {
/**
* Cubic ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Cubic
* @returns {number} Description.
*/
In: function ( k ) {
return k * k * k;
},
/**
* Cubic ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Cubic
* @returns {number} Description.
*/
Out: function ( k ) {
return --k * k * k + 1;
},
/**
* Cubic ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Cubic
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
@@ -56,20 +140,49 @@ Phaser.Easing = {
},
/**
* Quartic easing.
*
* @namespace Quartic
*/
Quartic: {
/**
* Quartic ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Quartic
* @returns {number} Description.
*/
In: function ( k ) {
return k * k * k * k;
},
/**
* Quartic ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Quartic
* @returns {number} Description.
*/
Out: function ( k ) {
return 1 - ( --k * k * k * k );
},
/**
* Quartic ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @returns {number} Description.
* @memberof Quartic
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
@@ -79,20 +192,49 @@ Phaser.Easing = {
},
/**
* Quintic easing.
*
* @namespace Quintic
*/
Quintic: {
/**
* Quintic ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Quintic
* @returns {number} Description.
*/
In: function ( k ) {
return k * k * k * k * k;
},
/**
* Quintic ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Quintic
* @returns {number} Description.
*/
Out: function ( k ) {
return --k * k * k * k * k + 1;
},
/**
* Quintic ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Quintic
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
@@ -102,20 +244,49 @@ Phaser.Easing = {
},
/**
* Sinusoidal easing.
*
* @namespace Sinusoidal
*/
Sinusoidal: {
/**
* Sinusoidal ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Sinusoidal
* @returns {number} Description.
*/
In: function ( k ) {
return 1 - Math.cos( k * Math.PI / 2 );
},
/**
* Sinusoidal ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Sinusoidal
* @returns {number} Description.
*/
Out: function ( k ) {
return Math.sin( k * Math.PI / 2 );
},
/**
* Sinusoidal ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Sinusoidal
* @returns {number} Description.
*/
InOut: function ( k ) {
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
@@ -124,20 +295,49 @@ Phaser.Easing = {
},
/**
* Exponential easing.
*
* @namespace Exponential
*/
Exponential: {
/**
* Exponential ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Exponential
* @returns {number} Description.
*/
In: function ( k ) {
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
},
/**
* Exponential ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Exponential
* @returns {number} Description.
*/
Out: function ( k ) {
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
},
/**
* Exponential ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Exponential
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( k === 0 ) return 0;
@@ -149,20 +349,49 @@ Phaser.Easing = {
},
/**
* Circular easing.
*
* @namespace Circular
*/
Circular: {
/**
* Circular ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Circular
* @returns {number} Description.
*/
In: function ( k ) {
return 1 - Math.sqrt( 1 - k * k );
},
/**
* Circular ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Circular
* @returns {number} Description.
*/
Out: function ( k ) {
return Math.sqrt( 1 - ( --k * k ) );
},
/**
* Circular ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Circular
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
@@ -172,8 +401,21 @@ Phaser.Easing = {
},
/**
* Elastic easing.
*
* @namespace Elastic
*/
Elastic: {
/**
* Elastic ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Elastic
* @returns {number} Description.
*/
In: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -185,6 +427,14 @@ Phaser.Easing = {
},
/**
* Elastic ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Elastic
* @returns {number} Description.
*/
Out: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -196,6 +446,14 @@ Phaser.Easing = {
},
/**
* Elastic ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Elastic
* @returns {number} Description.
*/
InOut: function ( k ) {
var s, a = 0.1, p = 0.4;
@@ -210,8 +468,21 @@ Phaser.Easing = {
},
/**
* Back easing.
*
* @namespace Back
*/
Back: {
/**
* Back ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Back
* @returns {number} Description.
*/
In: function ( k ) {
var s = 1.70158;
@@ -219,6 +490,14 @@ Phaser.Easing = {
},
/**
* Back ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Back
* @returns {number} Description.
*/
Out: function ( k ) {
var s = 1.70158;
@@ -226,6 +505,14 @@ Phaser.Easing = {
},
/**
* Back ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Back
* @returns {number} Description.
*/
InOut: function ( k ) {
var s = 1.70158 * 1.525;
@@ -236,14 +523,35 @@ Phaser.Easing = {
},
/**
* Bounce easing.
*
* @namespace Bounce
*/
Bounce: {
/**
* Bounce ease-in.
*
* @method In
* @param {number} k - Description.
* @memberof Bounce
* @returns {number} Description.
*/
In: function ( k ) {
return 1 - Phaser.Easing.Bounce.Out( 1 - k );
},
/**
* Bounce ease-out.
*
* @method Out
* @param {number} k - Description.
* @memberof Bounce
* @returns {number} Description.
*/
Out: function ( k ) {
if ( k < ( 1 / 2.75 ) ) {
@@ -266,6 +574,14 @@ Phaser.Easing = {
},
/**
* Bounce ease-in/out.
*
* @method InOut
* @param {number} k - Description.
* @memberof Bounce
* @returns {number} Description.
*/
InOut: function ( k ) {
if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5;
+261 -45
View File
@@ -1,52 +1,177 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Tween
*/
/**
* Tween constructor
* Create a new <code>Tween</code>.
*
* @param object {object} Target object will be affected by this tween.
* @param game {Phaser.Game} Current game instance.
* @class Phaser.Tween
* @constructor
* @param {object} object - Target object will be affected by this tween.
* @param {Phaser.Game} game - Current game instance.
*/
Phaser.Tween = function (object, game) {
/**
* Reference to the target object.
* @type {object}
* @property {object} _object
* @private
*/
this._object = object;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {object} _manager - Description.
* @private
*/
this._manager = this.game.tweens;
this._valuesStart = {};
this._valuesEnd = {};
this._valuesStartRepeat = {};
this._duration = 1000;
this._repeat = 0;
this._yoyo = false;
this._reversed = false;
this._delayTime = 0;
this._startTime = null;
this._easingFunction = Phaser.Easing.Linear.None;
this._interpolationFunction = Phaser.Math.linearInterpolation;
this._chainedTweens = [];
this._onStartCallback = null;
this._onStartCallbackFired = false;
this._onUpdateCallback = null;
this._onCompleteCallback = null;
/**
* @property {object} _valuesStart - Description.
* @private
*/
this._valuesStart = {};
/**
* @property {object} _valuesEnd - Description.
* @private
*/
this._valuesEnd = {};
/**
* @property {object} _valuesStartRepeat - Description.
* @private
*/
this._valuesStartRepeat = {};
/**
* @property {number} _duration - Description.
* @default
*/
this._duration = 1000;
/**
* @property {number} _repeat - Description.
* @private
* @default
*/
this._repeat = 0;
/**
* @property {bool} _yoyo - Description.
* @private
* @default
*/
this._yoyo = false;
/**
* @property {bool} _reversed - Description.
* @private
* @default
*/
this._reversed = false;
/**
* @property {number} _delayTime - Description.
* @private
* @default
*/
this._delayTime = 0;
/**
* @property {Description} _startTime - Description.
* @private
* @default null
*/
this._startTime = null;
/**
* @property {Description} _easingFunction - Description.
* @private
*/
this._easingFunction = Phaser.Easing.Linear.None;
/**
* @property {Description} _interpolationFunction - Description.
* @private
*/
this._interpolationFunction = Phaser.Math.linearInterpolation;
/**
* @property {Description} _chainedTweens - Description.
* @private
*/
this._chainedTweens = [];
/**
* @property {Description} _onStartCallback - Description.
* @private
* @default
*/
this._onStartCallback = null;
/**
* @property {bool} _onStartCallbackFired - Description.
* @private
* @default
*/
this._onStartCallbackFired = false;
/**
* @property {Description} _onUpdateCallback - Description.
* @private
* @default null
*/
this._onUpdateCallback = null;
/**
* @property {Description} _onCompleteCallback - Description.
* @private
* @default null
*/
this._onCompleteCallback = null;
/**
* @property {number} _pausedTime - Description.
* @private
* @default
*/
this._pausedTime = 0;
this._parent = null;
/**
* @property {bool} pendingDelete - Description.
* @default
*/
this.pendingDelete = false;
// Set all starting values present on the target object
for ( var field in object ) {
this._valuesStart[ field ] = parseFloat(object[field], 10);
}
// Set all starting values present on the target object
for ( var field in object ) {
this._valuesStart[ field ] = parseFloat(object[field], 10);
}
/**
* @property {Phaser.Signal} onStart - Description.
*/
this.onStart = new Phaser.Signal();
/**
* @property {Phaser.Signal} onComplete - Description.
*/
this.onComplete = new Phaser.Signal();
/**
* @property {bool} isRunning - Description.
* @default
*/
this.isRunning = false;
};
@@ -55,13 +180,16 @@ Phaser.Tween.prototype = {
/**
* Configure the Tween
* @param properties {object} Propertis you want to tween.
* @param [duration] {number} duration of this tween.
* @param [ease] {any} Easing function.
* @param [autoStart] {bool} Whether this tween will start automatically or not.
* @param [delay] {number} delay before this tween will start, defaults to 0 (no delay)
* @param [loop] {bool} Should the tween automatically restart once complete? (ignores any chained tweens)
* @return {Tween} Itself.
*
* @method to
* @param {object} properties - Properties you want to tween.
* @param {number} duration - Duration of this tween.
* @param {function} ease - Easing function.
* @param {bool} autoStart - Whether this tween will start automatically or not.
* @param {number} delay - Delay before this tween will start, defaults to 0 (no delay).
* @param {bool} 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 ) {
@@ -109,6 +237,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method start
* @param {number} time - Description.
* @return {Phaser.Tween} Itself.
*/
start: function ( time ) {
if (this.game === null || this._object === null) {
@@ -155,6 +290,12 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method stop
* @return {Phaser.Tween} Itself.
*/
stop: function () {
this._manager.remove(this);
@@ -164,6 +305,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method delay
* @param {number} amount - Description.
* @return {Phaser.Tween} Itself.
*/
delay: function ( amount ) {
this._delayTime = amount;
@@ -171,6 +319,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method repeat
* @param {number} times - How many times to repeat.
* @return {Phaser.Tween} Itself.
*/
repeat: function ( times ) {
this._repeat = times;
@@ -178,6 +333,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method yoyo
* @param {Phaser.Tween} yoyo - Description.
* @return {Phaser.Tween} Itself.
*/
yoyo: function( yoyo ) {
this._yoyo = yoyo;
@@ -185,6 +347,13 @@ Phaser.Tween.prototype = {
},
/**
* Set easing function.
*
* @method easing
* @param {function} easing - Description.
* @return {Phaser.Tween} Itself.
*/
easing: function ( easing ) {
this._easingFunction = easing;
@@ -192,6 +361,13 @@ Phaser.Tween.prototype = {
},
/**
* Set interpolation function.
*
* @method interpolation
* @param {function} interpolation - Description.
* @return {Phaser.Tween} Itself.
*/
interpolation: function ( interpolation ) {
this._interpolationFunction = interpolation;
@@ -199,6 +375,12 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method chain
* @return {Phaser.Tween} Itself.
*/
chain: function () {
this._chainedTweens = arguments;
@@ -215,7 +397,7 @@ Phaser.Tween.prototype = {
* .to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
* .loop();
*
* @method loop
* @return {Tween} Itself.
*/
loop: function() {
@@ -223,6 +405,13 @@ Phaser.Tween.prototype = {
return this;
},
/**
* Description.
*
* @method onStartCallback
* @param {object} callback - Description.
* @return {Phaser.Tween} Itself.
*/
onStartCallback: function ( callback ) {
this._onStartCallback = callback;
@@ -230,6 +419,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method onUpdateCallback
* @param {object} callback - Description.
* @return {Phaser.Tween} Itself.
*/
onUpdateCallback: function ( callback ) {
this._onUpdateCallback = callback;
@@ -237,6 +433,13 @@ Phaser.Tween.prototype = {
},
/**
* Description.
*
* @method onCompleteCallback
* @param {object} callback - Description.
* @return {Phaser.Tween} Itself.
*/
onCompleteCallback: function ( callback ) {
this._onCompleteCallback = callback;
@@ -244,19 +447,32 @@ Phaser.Tween.prototype = {
},
pause: function () {
this._paused = true;
this._pausedTime = this.game.time.now;
},
/**
* Pause.
*
* @method pause
*/
pause: function () {
this._paused = true;
},
resume: function () {
this._paused = false;
this._startTime += (this.game.time.now - this._pausedTime);
},
/**
* Resume.
*
* @method resume
*/
resume: function () {
this._paused = false;
this._startTime += this.game.time.pauseDuration;
},
/**
* Description.
*
* @method update
* @param {number} time - Description.
* @return {bool} Description.
*/
update: function ( time ) {
if (this.pendingDelete)
+57 -17
View File
@@ -1,18 +1,44 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.TweenManager
*/
/**
* Phaser - TweenManager
*
*
* @class Phaser.TweenManager
* @classdesc
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
* TweenManager is based heavily on tween.js by {@link http://soledadpenades.com|sole}.
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
* Please see {@link https://github.com/sole/tween.js} for a full list of contributors.
* @constructor
*
* @param {Phaser.Game} game - A reference to the currently running game.
*/
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 = [];
this.game.onPause.add(this.pauseAll, this);
@@ -22,11 +48,17 @@ Phaser.TweenManager = function (game) {
Phaser.TweenManager.prototype = {
/**
* Description.
* @property {string} REVISION
* @default
*/
REVISION: '11dev',
/**
* Get all the tween objects in an array.
* @return {Phaser.Tween[]} Array with all tween objects.
* @method getAll
* @returns {Phaser.Tween[]} Array with all tween objects.
*/
getAll: function () {
@@ -36,19 +68,20 @@ Phaser.TweenManager.prototype = {
/**
* Remove all tween objects.
* @method removeAll
*/
removeAll: function () {
this._add.length = 0;
this._tweens.length = 0;
this._tweens = [];
},
/**
* Add a new tween into the TweenManager.
*
* @param tween {Phaser.Tween} The tween object you want to add.
* @return {Phaser.Tween} The tween object you added to the manager.
* @method 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 ) {
@@ -57,11 +90,12 @@ Phaser.TweenManager.prototype = {
},
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @param obj {object} Object the tween will be run on.
* @return {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 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);
@@ -71,7 +105,8 @@ Phaser.TweenManager.prototype = {
/**
* Remove a tween from this manager.
*
* @param tween {Phaser.Tween} The tween object you want to remove.
* @method remove
* @param {Phaser.Tween} tween - The tween object you want to remove.
*/
remove: function ( tween ) {
@@ -88,7 +123,8 @@ Phaser.TweenManager.prototype = {
/**
* Update all the tween objects you added to this manager.
*
* @return {bool} Return false if there's no tween to update, otherwise return true.
* @method update
* @returns {bool} Return false if there's no tween to update, otherwise return true.
*/
update: function () {
@@ -126,8 +162,10 @@ Phaser.TweenManager.prototype = {
/**
* Pauses all currently running tweens.
*
* @method update
*/
pauseAll: function () {
pauseAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].pause();
@@ -137,8 +175,10 @@ Phaser.TweenManager.prototype = {
/**
* Pauses all currently paused tweens.
*
* @method resumeAll
*/
resumeAll: function () {
resumeAll: function () {
for (var i = this._tweens.length - 1; i >= 0; i--) {
this._tweens[i].resume();