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
+65 -84
View File
@@ -1,75 +1,59 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @module Phaser.Animation
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.AnimationManager
*/
/**
* The AnimationManager is used to add, play and update Phaser Animations.
* Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance.
*
* @class AnimationManager
* @class Phaser.AnimationManager
* @constructor
* @param {Phaser.Sprite} sprite A reference to the Game Object that owns this AnimationManager.
* @param {Phaser.Sprite} sprite - A reference to the Game Object that owns this AnimationManager.
*/
Phaser.AnimationManager = function (sprite) {
/**
* A reference to the parent Sprite that owns this AnimationManager.
* @property sprite
* @public
* @type {Phaser.Sprite}
* @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager.
*/
this.sprite = sprite;
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = sprite.game;
/**
* The currently displayed Frame of animation, if any.
* @property currentFrame
* @public
* @type {Phaser.Animation.Frame}
*/
/**
* @property {Phaser.Animation.Frame} currentFrame - The currently displayed Frame of animation, if any.
* @default
*/
this.currentFrame = null;
/**
* Should the animation data continue to update even if the Sprite.visible is set to false.
* @property updateIfVisible
* @public
* @type {Boolean}
* @default true
*/
/**
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
* @default
*/
this.updateIfVisible = true;
/**
* A temp. var for holding the currently playing Animations FrameData.
* @property _frameData
* @private
* @type {Phaser.Animation.FrameData}
*/
/**
* @property {Phaser.Animation.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
* @private
* @default
*/
this._frameData = null;
/**
* An internal object that stores all of the Animation instances.
* @property _anims
* @private
* @type {Object}
*/
/**
* @property {object} _anims - An internal object that stores all of the Animation instances.
* @private
*/
this._anims = {};
/**
* An internal object to help avoid gc.
* @property _outputFrames
* @private
* @type {Object}
*/
/**
* @property {object} _outputFrames - An internal object to help avoid gc.
* @private
*/
this._outputFrames = [];
};
@@ -82,7 +66,7 @@ Phaser.AnimationManager.prototype = {
*
* @method loadFrameData
* @private
* @param {Phaser.Animation.FrameData} frameData The FrameData set to load.
* @param {Phaser.Animation.FrameData} frameData - The FrameData set to load.
*/
loadFrameData: function (frameData) {
@@ -96,11 +80,11 @@ Phaser.AnimationManager.prototype = {
* Animations added in this way are played back with the play function.
*
* @method add
* @param {String} name The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".
* @param {Array} [frames=null] An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
* @param {Number} [frameRate=60] The speed at which the animation should play. The speed is given in frames per second.
* @param {Boolean} [loop=false] {bool} Whether or not the animation is looped or just plays once.
* @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false)
* @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".
* @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
* @param {boolean} [loop=false] {boolean} - Whether or not the animation is looped or just plays once.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
* @return {Phaser.Animation} The Animation object that was created.
*/
add: function (name, frames, frameRate, loop, useNumericIndex) {
@@ -141,9 +125,9 @@ Phaser.AnimationManager.prototype = {
* Check whether the frames in the given array are valid and exist.
*
* @method validateFrames
* @param {Array} frames An array of frames to be validated.
* @param {Boolean} [useNumericIndex=true] Validate the frames based on their numeric index (true) or string index (false)
* @return {Boolean} True if all given Frames are valid, otherwise false.
* @param {Array} frames - An array of frames to be validated.
* @param {boolean} [useNumericIndex=true] - Validate the frames based on their numeric index (true) or string index (false)
* @return {boolean} True if all given Frames are valid, otherwise false.
*/
validateFrames: function (frames, useNumericIndex) {
@@ -176,9 +160,9 @@ Phaser.AnimationManager.prototype = {
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @method play
* @param {String} name The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param {Number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {Boolean} [loop=null] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @return {Phaser.Animation} A reference to playing Animation instance.
*/
play: function (name, frameRate, loop) {
@@ -206,8 +190,8 @@ Phaser.AnimationManager.prototype = {
* The currentAnim property of the AnimationManager is automatically set to the animation given.
*
* @method stop
* @param {String} [name=null] The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
* @param {Boolean} [resetFrame=false] When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)
* @param {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
* @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)
*/
stop: function (name, resetFrame) {
@@ -236,7 +220,7 @@ Phaser.AnimationManager.prototype = {
*
* @method update
* @protected
* @return {Boolean} True if a new animation frame has been set, otherwise false.
* @return {boolean} True if a new animation frame has been set, otherwise false.
*/
update: function () {
@@ -273,24 +257,22 @@ Phaser.AnimationManager.prototype = {
};
/**
* @return {Phaser.Animation.FrameData} Returns the FrameData of the current animation.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", {
/**
* @method frameData
* @return {Phaser.Animation.FrameData} Returns the FrameData of the current animation.
*/
get: function () {
return this._frameData;
}
});
/**
* @return {number} Returns the total number of frames in the loaded FrameData, or -1 if no FrameData is loaded.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
/**
* @method frameTotal
* @return {Number} Returns the total number of frames in the loaded FrameData, or -1 if no FrameData is loaded.
*/
get: function () {
if (this._frameData)
@@ -305,6 +287,11 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
});
/**
* @return {boolean} Returns the paused state of the current animation.
*//**
* @param {boolean} value - Sets the paused state of the current animation.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "paused", {
get: function () {
@@ -321,12 +308,13 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", {
});
/**
* @return {number} Returns the index of the current frame.
*//**
* @param {number} value - Sets the current frame on the Sprite and updates the texture cache for display.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
/**
* @method frame
* @return {Number} Returns the index of the current frame.
*/
get: function () {
if (this.currentFrame)
@@ -336,10 +324,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
},
/**
* @method frame
* @param {Number} value Sets the current frame on the Sprite and updates the texture cache for display.
*/
set: function (value) {
if (this._frameData && this._frameData.getFrame(value) !== null)
@@ -354,12 +338,13 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
});
/**
* @return {string} Returns the name of the current frame if it has one.
*//**
* @param {string} value - Sets the current frame on the Sprite and updates the texture cache for display.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
/**
* @method frameName
* @return {String} Returns the name of the current frame if it has one.
*/
get: function () {
if (this.currentFrame)
@@ -369,10 +354,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
},
/**
* @method frameName
* @param {String} value Sets the current frame on the Sprite and updates the texture cache for display.
*/
set: function (value) {
if (this._frameData && this._frameData.getFrameByName(value) !== null)