mirror of
https://github.com/wassname/phaser.git
synced 2026-07-09 00:20:17 +08:00
1.0.3 release - fixed Text and Bitmap Fonts, Animation documentation and more examples
This commit is contained in:
+128
-79
@@ -1,37 +1,45 @@
|
||||
/**
|
||||
* FrameData
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
|
||||
*
|
||||
* @package Phaser.Animation.FrameData
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @class FrameData
|
||||
* @constructor
|
||||
*/
|
||||
Phaser.Animation.FrameData = function () {
|
||||
|
||||
/**
|
||||
* Local frame container.
|
||||
* @type {Phaser.Frame[]}
|
||||
* @private
|
||||
*/
|
||||
* Local array of frames.
|
||||
* @property _frames
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this._frames = [];
|
||||
|
||||
/**
|
||||
* Local frameName<->index container.
|
||||
* @private
|
||||
*/
|
||||
* Local array of frame names for name to index conversions.
|
||||
* @property _frameNames
|
||||
* @private
|
||||
* @type {Array}
|
||||
*/
|
||||
this._frameNames = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new frame.
|
||||
* @param frame {Frame} The frame you want to add.
|
||||
* @return {Frame} The frame you just added.
|
||||
*/
|
||||
/**
|
||||
* 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.
|
||||
* @return {Phaser.Animation.Frame} The frame that was just added.
|
||||
*/
|
||||
addFrame: function (frame) {
|
||||
|
||||
frame.index = this._frames.length;
|
||||
@@ -48,9 +56,11 @@ Phaser.Animation.FrameData.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a frame by its index.
|
||||
* @param index {number} Index of the frame you want to get.
|
||||
* @return {Frame} The frame you want.
|
||||
* Get a Frame by its numerical index.
|
||||
*
|
||||
* @method getFrame
|
||||
* @param {Number} index The index of the frame you want to get.
|
||||
* @return {Phaser.Animation.Frame} The frame, if found.
|
||||
*/
|
||||
getFrame: function (index) {
|
||||
|
||||
@@ -63,14 +73,16 @@ Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a frame by its name.
|
||||
* @param name {string} Name of the frame you want to get.
|
||||
* @return {Frame} The frame you want.
|
||||
*/
|
||||
/**
|
||||
* Get a Frame by its frame name.
|
||||
*
|
||||
* @method getFrameByName
|
||||
* @param {String} name The name of the frame you want to get.
|
||||
* @return {Phaser.Animation.Frame} The frame, if found.
|
||||
*/
|
||||
getFrameByName: function (name) {
|
||||
|
||||
if (this._frameNames[name] !== '')
|
||||
if (this._frameNames[name] && this._frameNames[name] !== '')
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
@@ -79,11 +91,13 @@ Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether there's a frame with given name.
|
||||
* @param name {string} Name of the frame you want to check.
|
||||
* @return {bool} True if frame with given name found, otherwise return false.
|
||||
*/
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
checkFrameName: function (name) {
|
||||
|
||||
if (this._frameNames[name] == null)
|
||||
@@ -96,11 +110,13 @@ Phaser.Animation.FrameData.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get ranges of frames in an array.
|
||||
* @param start {number} Start index of frames you want.
|
||||
* @param end {number} End index of frames you want.
|
||||
* @param [output] {Frame[]} result will be added into this array.
|
||||
* @return {Frame[]} Ranges of specific frames in an array.
|
||||
* 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.
|
||||
* @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) {
|
||||
|
||||
@@ -116,37 +132,45 @@ Phaser.Animation.FrameData.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all indexes of frames by giving their name.
|
||||
* @param [output] {number[]} result will be added into this array.
|
||||
* @return {number[]} Indexes of specific frames in an array.
|
||||
* Returns all of the Frames in this FrameData set where the frame index is found in the input array.
|
||||
* 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.
|
||||
* @return {Array} An array of all Frames in this FrameData set matching the given names or IDs.
|
||||
*/
|
||||
getFrameIndexes: function (output) {
|
||||
getFrames: function (frames, useNumericIndex, output) {
|
||||
|
||||
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
if (typeof frames === "undefined" || frames.length == 0)
|
||||
{
|
||||
output.push(i);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the frame indexes by giving the frame names.
|
||||
* @param [output] {number[]} result will be added into this array.
|
||||
* @return {number[]} Names of specific frames in an array.
|
||||
*/
|
||||
getFrameIndexesByName: function (input) {
|
||||
|
||||
var output = [];
|
||||
|
||||
for (var i = 0; i < input.length; i++)
|
||||
{
|
||||
if (this.getFrameByName(input[i]))
|
||||
// No input array, so we loop through all frames
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
// We only need the indexes
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Input array given, loop through that instead
|
||||
for (var i = 0, len = frames.length; i < len; i++)
|
||||
{
|
||||
// Does the input array contain names or indexes?
|
||||
if (useNumericIndex)
|
||||
{
|
||||
// The actual frame
|
||||
output.push(this.getFrame(input[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// The actual frame
|
||||
output.push(this.getFrameByName(input[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,35 +178,60 @@ Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all frames in this frame data.
|
||||
* @return {Frame[]} All the frames in an array.
|
||||
*/
|
||||
getAllFrames: function () {
|
||||
return this._frames;
|
||||
},
|
||||
/**
|
||||
* Returns all of the Frame indexes in this FrameData set.
|
||||
* 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.
|
||||
* @return {Array} An array of all Frame indexes matching the given names or IDs.
|
||||
*/
|
||||
getFrameIndexes: function (input, useNumericIndex, output) {
|
||||
|
||||
/**
|
||||
* Get All frames with specific ranges.
|
||||
* @param range {number[]} Ranges in an array.
|
||||
* @return {Frame[]} All frames in an array.
|
||||
*/
|
||||
getFrames: function (range) {
|
||||
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
|
||||
var output = [];
|
||||
|
||||
for (var i = 0; i < range.length; i++)
|
||||
if (typeof frames === "undefined" || frames.length == 0)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
// No input array, so we loop through all frames
|
||||
for (var i = 0, len = this._frames.length; i < len; i++)
|
||||
{
|
||||
output.push(this._frames[i].index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Input array given, loop through that instead
|
||||
for (var i = 0, len = input.length; i < len; i++)
|
||||
{
|
||||
// Does the input array contain names or indexes?
|
||||
if (useNumericIndex)
|
||||
{
|
||||
output.push(input[i].index);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Phaser.Animation.FrameData.prototype, "total", {
|
||||
|
||||
/**
|
||||
* Returns the total number of frames in this FrameData set.
|
||||
*
|
||||
* @method total
|
||||
* @return {Number} The total number of frames in this FrameData set.
|
||||
*/
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user