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
+42 -15
View File
@@ -1,7 +1,7 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Animation
*/
@@ -92,7 +92,18 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope
*/
this._frameIndex = 0;
/**
* @property {number} _frameDiff
* @private
* @default
*/
this._frameDiff = 0;
/**
* @property {number} _frameSkip
* @private
* @default
*/
this._frameSkip = 1;
/**
@@ -108,9 +119,9 @@ Phaser.Animation.prototype = {
* Plays this animation.
*
* @method play
* @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 this Animation instance.
* @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 this Animation instance.
*/
play: function (frameRate, loop) {
@@ -169,7 +180,7 @@ Phaser.Animation.prototype = {
* Stops playback of this animation and set it to a finished state. If a resetFrame is provided it will stop playback and set frame to the first in the animation.
*
* @method stop
* @param {Boolean} [resetFrame=false] If true after the animation stops the currentFrame value will be set to the first frame in this animation.
* @param {boolean} [resetFrame=false] - If true after the animation stops the currentFrame value will be set to the first frame in this animation.
*/
stop: function (resetFrame) {
@@ -287,6 +298,14 @@ Phaser.Animation.prototype = {
};
/**
* Sets the paused state of the Animation.
* @param {boolean} value - Set to true to pause the animation or false to resume it if previous paused.
*
*//**
*
* Returns the paused state of the Animation.
* @returns {boolean}
*
*/
Object.defineProperty(Phaser.Animation.prototype, "paused", {
@@ -318,12 +337,14 @@ Object.defineProperty(Phaser.Animation.prototype, "paused", {
});
/**
*
* Returns the total number of frames in this Animation.
* @return {number}
*
*/
Object.defineProperty(Phaser.Animation.prototype, "frameTotal", {
/**
* @method frameTotal
* @return {Number} The total number of frames in this animation.
*/
get: function () {
return this._frames.length;
}
@@ -369,12 +390,18 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", {
});
/*
* Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers.
* For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large'
* You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4);
* The zeroPad value dictates how many zeroes to add in front of the numbers (if any)
*/
/**
* Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers.
* For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large'
* You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4);
*
* @param {string} prefix - The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'.
* @param {number} min - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the min is 1.
* @param {number} max - The number to count up to. If your frames are named 'explosion_0001' to 'explosion_0034' the max is 34.
* @param {string} [suffix=''] - The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'.
* @param {number} [zeroPad=0] - The number of zeroes to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
* @method generateFrameNames
*/
Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPad) {
if (typeof suffix == 'undefined') { suffix = ''; }
+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)
+44 -100
View File
@@ -1,180 +1,124 @@
/**
* @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.Frame
*/
/**
* A Frame is a single frame of an animation and is part of a FrameData collection.
*
* @class Frame
* @class Phaser.Animation.Frame
* @constructor
* @param {Number} index The index of this Frame within the FrameData set it is being added to.
* @param {Number} x X position of the frame within the texture image.
* @param {Number} y Y position of the frame within the texture image.
* @param {Number} width Width of the frame within the texture image.
* @param {Number} height Height of the frame within the texture image.
* @param {String} name The name of the frame. In Texture Atlas data this is usually set to the filename.
* @param {String} uuid Internal UUID key.
* @param {number} index - The index of this Frame within the FrameData set it is being added to.
* @param {number} x - X position of the frame within the texture image.
* @param {number} y - Y position of the frame within the texture image.
* @param {number} width - Width of the frame within the texture image.
* @param {number} height - Height of the frame within the texture image.
* @param {string} name - The name of the frame. In Texture Atlas data this is usually set to the filename.
* @param {string} uuid - Internal UUID key.
*/
Phaser.Animation.Frame = function (index, x, y, width, height, name, uuid) {
/**
* The index of this Frame within the FrameData set it is being added to.
* @property index
* @public
* @type {Number}
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
*/
this.index = index;
/**
* X position within the image to cut from.
* @property x
* @public
* @type {Number}
* @property {number} x - X position within the image to cut from.
*/
this.x = x;
/**
* Y position within the image to cut from.
* @property y
* @public
* @type {Number}
* @property {number} y - Y position within the image to cut from.
*/
this.y = y;
/**
* Width of the frame.
* @property width
* @public
* @type {Number}
* @property {number} width - Width of the frame.
*/
this.width = width;
/**
* Height of the frame.
* @property height
* @public
* @type {Number}
* @property {number} height - Height of the frame.
*/
this.height = height;
/**
* Useful for Texture Atlas files. (is set to the filename value)
* @property name
* @public
* @type {String}
* @property {string} name - Useful for Texture Atlas files (is set to the filename value).
*/
this.name = name;
/**
* A link to the PIXI.TextureCache entry
* @property uuid
* @public
* @type {String}
* @property {string} uuid - A link to the PIXI.TextureCache entry.
*/
this.uuid = uuid;
/**
* center X position within the image to cut from.
* @property centerX
* @public
* @type {Number}
* @property {number} centerX - Center X position within the image to cut from.
*/
this.centerX = Math.floor(width / 2);
/**
* center Y position within the image to cut from.
* @property centerY
* @public
* @type {Number}
* @property {number} centerY - Center Y position within the image to cut from.
*/
this.centerY = Math.floor(height / 2);
/**
* The distance from the top left to the bottom-right of this Frame.
* @property distance
* @public
* @type {Number}
* @property {number} distance - The distance from the top left to the bottom-right of this Frame.
*/
this.distance = Phaser.Math.distance(0, 0, width, height);
/**
* Rotated? (not yet implemented)
* @property rotated
* @public
* @type {Boolean}
* @default false
* @property {bool} rotated - Rotated? (not yet implemented)
* @default
*/
this.rotated = false;
/**
* Either cw or ccw, rotation is always 90 degrees.
* @property rotationDirection
* @public
* @type {String}
* @default "cw"
* @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees.
* @default 'cw'
*/
this.rotationDirection = 'cw';
/**
* Was it trimmed when packed?
* @property trimmed
* @public
* @type {Boolean}
* @property {bool} trimmed - Was it trimmed when packed?
* @default
*/
this.trimmed = false;
/**
* Width of the original sprite.
* @property sourceSizeW
* @public
* @type {Number}
* @property {number} sourceSizeW - Width of the original sprite.
*/
this.sourceSizeW = width;
/**
* Height of the original sprite.
* @property sourceSizeH
* @public
* @type {Number}
* @property {number} sourceSizeH - Height of the original sprite.
*/
this.sourceSizeH = height;
/**
* X position of the trimmed sprite inside original sprite.
* @property spriteSourceSizeX
* @public
* @type {Number}
* @default 0
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeX = 0;
/**
* Y position of the trimmed sprite inside original sprite.
* @property spriteSourceSizeY
* @public
* @type {Number}
* @default 0
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeY = 0;
/**
* Width of the trimmed sprite.
* @property spriteSourceSizeW
* @public
* @type {Number}
* @default 0
* @property {number} spriteSourceSizeW - Width of the trimmed sprite.
* @default
*/
this.spriteSourceSizeW = 0;
/**
* Height of the trimmed sprite.
* @property spriteSourceSizeH
* @public
* @type {Number}
* @default 0
* @property {number} spriteSourceSizeH - Height of the trimmed sprite.
* @default
*/
this.spriteSourceSizeH = 0;
@@ -186,13 +130,13 @@ Phaser.Animation.Frame.prototype = {
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
*
* @method setTrim
* @param {Boolean} trimmed If this frame was trimmed or not.
* @param {Number} actualWidth The width of the frame before being trimmed.
* @param {Number} actualHeight The height of the frame before being trimmed.
* @param {Number} destX The destination X position of the trimmed frame for display.
* @param {Number} destY The destination Y position of the trimmed frame for display.
* @param {Number} destWidth The destination width of the trimmed frame for display.
* @param {Number} destHeight The destination height of the trimmed frame for display.
* @param {bool} trimmed - If this frame was trimmed or not.
* @param {number} actualWidth - The width of the frame before being trimmed.
* @param {number} actualHeight - The height of the frame before being trimmed.
* @param {number} destX - The destination X position of the trimmed frame for display.
* @param {number} destY - The destination Y position of the trimmed frame for display.
* @param {number} destWidth - The destination width of the trimmed frame for display.
* @param {number} destHeight - The destination height of the trimmed frame for display.
*/
setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
+26 -29
View File
@@ -1,32 +1,29 @@
/**
* @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.FrameData
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.FrameData
*/
/**
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
*
* @class FrameData
* @class Phaser.Animation.FrameData
* @constructor
*/
Phaser.Animation.FrameData = function () {
/**
* Local array of frames.
* @property _frames
* @private
* @type {Array}
*/
/**
* @property {Array} _frames - Local array of frames.
* @private
*/
this._frames = [];
/**
* Local array of frame names for name to index conversions.
* @property _frameNames
* @private
* @type {Array}
*/
/**
* @property {Array} _frameNames - Local array of frame names for name to index conversions.
* @private
*/
this._frameNames = [];
};
@@ -37,7 +34,7 @@ Phaser.Animation.FrameData.prototype = {
* Adds a new Frame to this FrameData collection. Typically called by the Animation.Parser and not directly.
*
* @method addFrame
* @param {Phaser.Animation.Frame} frame The frame to add to this FrameData set.
* @param {Phaser.Animation.Frame} frame - The frame to add to this FrameData set.
* @return {Phaser.Animation.Frame} The frame that was just added.
*/
addFrame: function (frame) {
@@ -59,7 +56,7 @@ Phaser.Animation.FrameData.prototype = {
* Get a Frame by its numerical index.
*
* @method getFrame
* @param {Number} index The index of the frame you want to get.
* @param {number} index - The index of the frame you want to get.
* @return {Phaser.Animation.Frame} The frame, if found.
*/
getFrame: function (index) {
@@ -77,7 +74,7 @@ Phaser.Animation.FrameData.prototype = {
* Get a Frame by its frame name.
*
* @method getFrameByName
* @param {String} name The name of the frame you want to get.
* @param {string} name - The name of the frame you want to get.
* @return {Phaser.Animation.Frame} The frame, if found.
*/
getFrameByName: function (name) {
@@ -95,8 +92,8 @@ Phaser.Animation.FrameData.prototype = {
* Check if there is a Frame with the given name.
*
* @method checkFrameName
* @param {String} name The name of the frame you want to check.
* @return {Boolean} True if the frame is found, otherwise false.
* @param {string} name - The name of the frame you want to check.
* @return {boolean} True if the frame is found, otherwise false.
*/
checkFrameName: function (name) {
@@ -113,9 +110,9 @@ Phaser.Animation.FrameData.prototype = {
* Returns a range of frames based on the given start and end frame indexes and returns them in an Array.
*
* @method getFrameRange
* @param {Number} start The starting frame index.
* @param {Number} end The ending frame index.
* @param {Array} [output] Optional array. If given the results will be appended to the end of this Array.
* @param {number} start - The starting frame index.
* @param {number} end - The ending frame index.
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of Frames between the start and end index values, or an empty array if none were found.
*/
getFrameRange: function (start, end, output) {
@@ -136,9 +133,9 @@ Phaser.Animation.FrameData.prototype = {
* The frames are returned in the output array, or if none is provided in a new Array object.
*
* @method getFrames
* @param {Array} frames An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned.
* @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false)
* @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created.
* @param {Array} frames - An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false)
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of all Frames in this FrameData set matching the given names or IDs.
*/
getFrames: function (frames, useNumericIndex, output) {
@@ -183,9 +180,9 @@ Phaser.Animation.FrameData.prototype = {
* The frames indexes are returned in the output array, or if none is provided in a new Array object.
*
* @method getFrameIndexes
* @param {Array} frames An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned.
* @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false)
* @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created.
* @param {Array} frames - An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false)
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of all Frame indexes matching the given names or IDs.
*/
getFrameIndexes: function (frames, useNumericIndex, output) {
+27 -21
View File
@@ -1,23 +1,26 @@
/**
* @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.Animation.Parser
*/
/**
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
*
* @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
* @class Phaser.Animation.Parser
*/
Phaser.Animation.Parser = {
/**
* Parse a Sprite Sheet and extract the animation frame data from it.
*
* @method spriteSheet
* @param {Phaser.Game} game A reference to the currently running game.
* @param {String} key The Game.Cache asset key of the Sprite Sheet image.
* @param {Number} frameWidth The fixed width of each frame of the animation. If negative, indicates how many columns there are.
* @param {Number} frameHeight The fixed height of each frame of the animation. If negative, indicates how many rows there are.
* @param {Number} [frameMax=-1] The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames".
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {string} key - The Game.Cache asset key of the Sprite Sheet image.
* @param {number} frameWidth - The fixed width of each frame of the animation.
* @param {number} frameHeight - The fixed height of each frame of the animation.
* @param {number} [frameMax=-1] - The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames".
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
*/
spriteSheet: function (game, key, frameWidth, frameHeight, frameMax) {
@@ -32,14 +35,17 @@ Phaser.Animation.Parser = {
var width = img.width;
var height = img.height;
if (frameWidth <= 0)
{
frameWidth = Math.floor(-width/Math.min(-1, frameWidth));
frameWidth = Math.floor(-width / Math.min(-1, frameWidth));
}
if (frameHeight <= 0)
{
frameHeight = Math.floor(-height/Math.min(-1, frameHeight));
frameHeight = Math.floor(-height / Math.min(-1, frameHeight));
}
var row = Math.round(width / frameWidth);
var column = Math.round(height / frameHeight);
var total = row * column;
@@ -91,9 +97,9 @@ Phaser.Animation.Parser = {
* Parse the JSON data and extract the animation frame data from it.
*
* @method JSONData
* @param {Phaser.Game} game A reference to the currently running game.
* @param {Object} json The JSON data from the Texture Atlas. Must be in Array format.
* @param {String} cacheKey The Game.Cache asset key of the texture image.
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Object} json - The JSON data from the Texture Atlas. Must be in Array format.
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
*/
JSONData: function (game, json, cacheKey) {
@@ -162,9 +168,9 @@ Phaser.Animation.Parser = {
* Parse the JSON data and extract the animation frame data from it.
*
* @method JSONDataHash
* @param {Phaser.Game} game A reference to the currently running game.
* @param {Object} json The JSON data from the Texture Atlas. Must be in JSON Hash format.
* @param {String} cacheKey The Game.Cache asset key of the texture image.
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
*/
JSONDataHash: function (game, json, cacheKey) {
@@ -236,9 +242,9 @@ Phaser.Animation.Parser = {
* Parse the XML data and extract the animation frame data from it.
*
* @method XMLData
* @param {Phaser.Game} game A reference to the currently running game.
* @param {Object} xml The XML data from the Texture Atlas. Must be in Starling XML format.
* @param {String} cacheKey The Game.Cache asset key of the texture image.
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Object} xml - The XML data from the Texture Atlas. Must be in Starling XML format.
* @param {string} cacheKey - The Game.Cache asset key of the texture image.
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
*/
XMLData: function (game, xml, cacheKey) {