mirror of
https://github.com/wassname/phaser.git
synced 2026-07-03 17:10:40 +08:00
1.0.3 release - fixed Text and Bitmap Fonts, Animation documentation and more examples
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
var Phaser = Phaser || {
|
||||
|
||||
VERSION: '1.0.2',
|
||||
VERSION: '1.0.3',
|
||||
GAMES: [],
|
||||
AUTO: 0,
|
||||
CANVAS: 1,
|
||||
|
||||
+150
-36
@@ -1,43 +1,126 @@
|
||||
/**
|
||||
* Animation
|
||||
*
|
||||
* An Animation instance contains a single animation and the controls to play it.
|
||||
* It is created by the AnimationManager and belongs to Game Objects such as Sprite.
|
||||
*
|
||||
* @package Phaser.Animation
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*
|
||||
* @param parent {Sprite} Owner sprite of this animation.
|
||||
* @param frameData {FrameData} The FrameData object contains animation data.
|
||||
* @param name {string} Unique name of this animation.
|
||||
* @param frames {number[]/string[]} An array of numbers or strings indicating what frames to play in what order.
|
||||
* @param delay {number} Time between frames in ms.
|
||||
* @param looped {bool} Whether or not the animation is looped or just plays once.
|
||||
* @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
|
||||
*/
|
||||
Phaser.Animation = function (game, parent, frameData, name, frames, delay, looped) {
|
||||
|
||||
/**
|
||||
* An Animation instance contains a single animation and the controls to play it.
|
||||
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
|
||||
*
|
||||
* @class Animation
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game A reference to the currently running game.
|
||||
* @param {Phaser.Sprite} parent A reference to the owner of this Animation.
|
||||
* @param {String} name The unique name for this animation, used in playback commands.
|
||||
* @param {Phaser.Animation.FrameData} frameData The FrameData object that contains all frames used by this Animation.
|
||||
* @param {Mixed} frames An array of numbers or strings indicating which frames to play in which order.
|
||||
* @param {Number} delay The time between each frame of the animation, given in ms.
|
||||
* @param {Boolean} looped Should this animation loop or play through once.
|
||||
*/
|
||||
Phaser.Animation = function (game, parent, name, frameData, frames, delay, looped) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* A reference to the parent Sprite that owns this Animation.
|
||||
* @property _parent
|
||||
* @private
|
||||
* @type {Phaser.Sprite}
|
||||
*/
|
||||
this._parent = parent;
|
||||
|
||||
/**
|
||||
* The FrameData the Animation uses.
|
||||
* @property _frameData
|
||||
* @private
|
||||
* @type {Phaser.FrameData}
|
||||
*/
|
||||
this._frameData = frameData;
|
||||
|
||||
/**
|
||||
* The user defined name given to this Animation.
|
||||
* @property name
|
||||
* @public
|
||||
* @type {String}
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property _frames
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this._frames = frames;
|
||||
this._frameData = frameData;
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* The delay in ms between each frame of the Animation.
|
||||
* @property delay
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.delay = 1000 / delay;
|
||||
|
||||
/**
|
||||
* The loop state of the Animation.
|
||||
* @property looped
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.looped = looped;
|
||||
|
||||
/**
|
||||
* The finished state of the Animation. Set to true once playback completes, false during playback.
|
||||
* @property isFinished
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* default true
|
||||
*/
|
||||
this.isFinished = false;
|
||||
|
||||
/**
|
||||
* The playing state of the Animation. Set to false once playback completes, true during playback.
|
||||
* @property isPlaying
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* default false
|
||||
*/
|
||||
this.isPlaying = false;
|
||||
|
||||
/**
|
||||
* @property _frameIndex
|
||||
* @private
|
||||
* @type {Number}
|
||||
* default 0
|
||||
*/
|
||||
this._frameIndex = 0;
|
||||
|
||||
/**
|
||||
* The currently displayed frame of the Animation.
|
||||
* @property currentFrame
|
||||
* @public
|
||||
* @type {Phaser.Animation.Frame}
|
||||
*/
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.prototype = {
|
||||
|
||||
/**
|
||||
* Play this animation.
|
||||
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
play: function (frameRate, loop) {
|
||||
|
||||
@@ -65,14 +148,20 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
this._parent.events.onAnimationStart.dispatch(this._parent, this);
|
||||
|
||||
if (this._parent.events)
|
||||
{
|
||||
this._parent.events.onAnimationStart.dispatch(this._parent, this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Play this animation from the first frame.
|
||||
/**
|
||||
* Sets this animation back to the first frame and restarts the animation.
|
||||
*
|
||||
* @method restart
|
||||
*/
|
||||
restart: function () {
|
||||
|
||||
@@ -88,12 +177,15 @@ Phaser.Animation.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop playing animation and set it finished.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
stop: function (resetFrame) {
|
||||
|
||||
if (typeof resetFrame == 'undefined') { resetFrame = false; }
|
||||
if (typeof resetFrame === 'undefined') { resetFrame = false; }
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
@@ -105,8 +197,10 @@ Phaser.Animation.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Update animation frames.
|
||||
/**
|
||||
* Updates this animation. Called automatically by the AnimationManager.
|
||||
*
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
@@ -144,8 +238,10 @@ Phaser.Animation.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean up animation memory.
|
||||
/**
|
||||
* Cleans up this animation ready for deletion. Nulls all values and references.
|
||||
*
|
||||
* @method destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
@@ -158,14 +254,20 @@ Phaser.Animation.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Animation complete callback method.
|
||||
/**
|
||||
* Called internally when the animation finishes playback. Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent.
|
||||
*
|
||||
* @method onComplete
|
||||
*/
|
||||
onComplete: function () {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
|
||||
|
||||
if (this._parent.events)
|
||||
{
|
||||
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +275,10 @@ Phaser.Animation.prototype = {
|
||||
|
||||
Object.defineProperty(Phaser.Animation.prototype, "frameTotal", {
|
||||
|
||||
/**
|
||||
* @method frameTotal
|
||||
* @return {Number} The total number of frames in this animation.
|
||||
*/
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
}
|
||||
@@ -181,6 +287,10 @@ Object.defineProperty(Phaser.Animation.prototype, "frameTotal", {
|
||||
|
||||
Object.defineProperty(Phaser.Animation.prototype, "frame", {
|
||||
|
||||
/**
|
||||
* @method frame
|
||||
* @return {Animation.Frame} Returns the current frame, or if not set the index of the most recent frame.
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
if (this.currentFrame !== null)
|
||||
@@ -194,6 +304,10 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method frame
|
||||
* @return {Number} Sets the current frame to the given frame index and updates the texture cache.
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
|
||||
@@ -1,44 +1,89 @@
|
||||
/**
|
||||
* AnimationManager
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Any Game Object that supports animation contains a single AnimationManager instance. It is used to add,
|
||||
* play and update Phaser.Animation objects.
|
||||
*
|
||||
* @package Phaser.Components.AnimationManager
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @class AnimationManager
|
||||
* @constructor
|
||||
* @param {Phaser.Sprite} sprite A reference to the Game Object that owns this AnimationManager.
|
||||
*/
|
||||
Phaser.AnimationManager = function (sprite) {
|
||||
|
||||
/**
|
||||
* Data contains animation frames.
|
||||
* @type {FrameData}
|
||||
*/
|
||||
this._frameData = null;
|
||||
|
||||
/**
|
||||
* Keeps track of the current frame of the animation.
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
|
||||
/**
|
||||
* A reference to the parent Sprite that owns this AnimationManager.
|
||||
* @property sprite
|
||||
* @public
|
||||
* @type {Phaser.Sprite}
|
||||
*/
|
||||
this.sprite = sprite;
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @public
|
||||
* @type {Phaser.Game}
|
||||
*/
|
||||
this.game = sprite.game;
|
||||
|
||||
/**
|
||||
* The currently displayed Frame of animation, if any.
|
||||
* @property currentFrame
|
||||
* @public
|
||||
* @type {Phaser.Animation.Frame}
|
||||
*/
|
||||
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
|
||||
*/
|
||||
this.updateIfVisible = true;
|
||||
|
||||
/**
|
||||
* A temp. var for holding the currently playing Animations FrameData.
|
||||
* @property _frameData
|
||||
* @private
|
||||
* @type {Phaser.Animation.FrameData}
|
||||
*/
|
||||
this._frameData = null;
|
||||
|
||||
/**
|
||||
* An internal object that stores all of the Animation instances.
|
||||
* @property _anims
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this._anims = {};
|
||||
|
||||
this.updateIfVisible = true;
|
||||
/**
|
||||
* An internal object to help avoid gc.
|
||||
* @property _outputFrames
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
this._outputFrames = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.AnimationManager.prototype = {
|
||||
|
||||
|
||||
/**
|
||||
* Load animation frame data.
|
||||
* @param frameData Data to be loaded.
|
||||
*/
|
||||
/**
|
||||
* Loads FrameData into the internal temporary vars and resets the frame index to zero.
|
||||
* This is called automatically when a new Sprite is created.
|
||||
*
|
||||
* @method loadFrameData
|
||||
* @private
|
||||
* @param {Phaser.Animation.FrameData} frameData The FrameData set to load.
|
||||
*/
|
||||
loadFrameData: function (frameData) {
|
||||
|
||||
this._frameData = frameData;
|
||||
@@ -47,28 +92,30 @@ Phaser.AnimationManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new animation.
|
||||
* @param name {string} What this animation should be called (e.g. "run").
|
||||
* @param frames {any[]} An array of numbers/strings indicating what frames to play in what order (e.g. [1, 2, 3] or ['run0', 'run1', run2]).
|
||||
* @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps).
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
* @param useNumericIndex {bool} Use number indexes instead of string indexes?
|
||||
* @return {Animation} The Animation that was created
|
||||
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
|
||||
* 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)
|
||||
* @return {Phaser.Animation} The Animation object that was created.
|
||||
*/
|
||||
add: function (name, frames, frameRate, loop, useNumericIndex) {
|
||||
|
||||
frames = frames || null;
|
||||
frameRate = frameRate || 60;
|
||||
|
||||
if (typeof loop == 'undefined') { loop = false; }
|
||||
if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; }
|
||||
|
||||
if (this._frameData == null)
|
||||
{
|
||||
console.warn('No frameData available for Phaser.Animation ' + name);
|
||||
console.warn('No FrameData available for Phaser.Animation ' + name);
|
||||
return;
|
||||
}
|
||||
|
||||
frameRate = frameRate || 60;
|
||||
|
||||
if (typeof loop === 'undefined') { loop = false; }
|
||||
if (typeof useNumericIndex === 'undefined') { useNumericIndex = true; }
|
||||
|
||||
// Create the signals the AnimationManager will emit
|
||||
if (this.sprite.events.onAnimationStart == null)
|
||||
{
|
||||
@@ -77,25 +124,11 @@ Phaser.AnimationManager.prototype = {
|
||||
this.sprite.events.onAnimationLoop = new Phaser.Signal();
|
||||
}
|
||||
|
||||
if (frames == null)
|
||||
{
|
||||
frames = this._frameData.getFrameIndexes();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.validateFrames(frames, useNumericIndex) == false)
|
||||
{
|
||||
console.warn('Invalid frames given to Phaser.Animation ' + name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._outputFrames.length = 0;
|
||||
|
||||
if (useNumericIndex == false)
|
||||
{
|
||||
frames = this._frameData.getFrameIndexesByName(frames);
|
||||
}
|
||||
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
|
||||
|
||||
this._anims[name] = new Phaser.Animation(this.game, this.sprite, this._frameData, name, frames, frameRate, loop);
|
||||
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
@@ -105,10 +138,12 @@ Phaser.AnimationManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Check whether the frames is valid.
|
||||
* @param frames {any[]} Frames to be validated.
|
||||
* @param useNumericIndex {bool} Does these frames use number indexes or string indexes?
|
||||
* @return {bool} True if they're valid, otherwise return false.
|
||||
* 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.
|
||||
*/
|
||||
validateFrames: function (frames, useNumericIndex) {
|
||||
|
||||
@@ -137,16 +172,17 @@ Phaser.AnimationManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Play animation with specific name.
|
||||
* @param name {string} The string name of the animation you want to play.
|
||||
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
|
||||
* 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.
|
||||
* @return {Phaser.Animation} A reference to playing Animation instance.
|
||||
*/
|
||||
play: function (name, frameRate, loop) {
|
||||
|
||||
frameRate = frameRate || null;
|
||||
loop = loop || null;
|
||||
|
||||
if (this._anims[name])
|
||||
{
|
||||
if (this.currentAnim == this._anims[name])
|
||||
@@ -166,8 +202,12 @@ Phaser.AnimationManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop animation. If a name is given that specific animation is stopped, otherwise the current one is stopped.
|
||||
* Current animation will be automatically set to the stopped one.
|
||||
* Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped.
|
||||
* 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)
|
||||
*/
|
||||
stop: function (name, resetFrame) {
|
||||
|
||||
@@ -192,8 +232,11 @@ Phaser.AnimationManager.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Update animation and parent sprite's bounds.
|
||||
* Returns true if a new frame has been set, otherwise false.
|
||||
* The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
|
||||
*
|
||||
* @method update
|
||||
* @protected
|
||||
* @return {Boolean} True if a new animation frame has been set, otherwise false.
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
@@ -213,8 +256,10 @@ Phaser.AnimationManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all related references
|
||||
/**
|
||||
* Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation.
|
||||
*
|
||||
* @method destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
@@ -230,6 +275,10 @@ Phaser.AnimationManager.prototype = {
|
||||
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", {
|
||||
|
||||
/**
|
||||
* @method frameData
|
||||
* @return {Phaser.Animation.FrameData} Returns the FrameData of the current animation.
|
||||
*/
|
||||
get: function () {
|
||||
return this._frameData;
|
||||
}
|
||||
@@ -238,6 +287,10 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", {
|
||||
|
||||
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)
|
||||
@@ -254,6 +307,10 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
|
||||
|
||||
Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
|
||||
|
||||
/**
|
||||
* @method frame
|
||||
* @return {Number} Returns the index of the current frame.
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
if (this.currentFrame)
|
||||
@@ -264,8 +321,8 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
* @method frame
|
||||
* @param {Number} value Sets the current frame on the Sprite and updates the texture cache for display.
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
@@ -283,6 +340,10 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
|
||||
|
||||
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)
|
||||
@@ -292,6 +353,10 @@ 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))
|
||||
|
||||
+137
-77
@@ -1,123 +1,181 @@
|
||||
/**
|
||||
* Frame
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
||||
*
|
||||
* @package Phaser.Animation.Frame
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @class 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.
|
||||
*/
|
||||
Phaser.Animation.Frame = function (x, y, width, height, name, uuid) {
|
||||
Phaser.Animation.Frame = function (index, x, y, width, height, name, uuid) {
|
||||
|
||||
/**
|
||||
* X position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
* The index of this Frame within the FrameData set it is being added to.
|
||||
* @property index
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
/**
|
||||
* X position within the image to cut from.
|
||||
* @property x
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.x = x;
|
||||
|
||||
/**
|
||||
* Y position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
* Y position within the image to cut from.
|
||||
* @property y
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.y = y;
|
||||
|
||||
/**
|
||||
* Width of the frame.
|
||||
* @type {number}
|
||||
*/
|
||||
* Width of the frame.
|
||||
* @property width
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* Height of the frame.
|
||||
* @type {number}
|
||||
*/
|
||||
* Height of the frame.
|
||||
* @property height
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* center X position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
this.centerX = Math.floor(width / 2);
|
||||
|
||||
/**
|
||||
* center Y position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
/**
|
||||
* Useful for Sprite Sheets.
|
||||
* @type {number}
|
||||
*/
|
||||
this.index = 0;
|
||||
|
||||
/**
|
||||
* Useful for Texture Atlas files. (is set to the filename value)
|
||||
*/
|
||||
* Useful for Texture Atlas files. (is set to the filename value)
|
||||
* @property name
|
||||
* @public
|
||||
* @type {String}
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* A link to the PIXI.TextureCache entry
|
||||
*/
|
||||
* A link to the PIXI.TextureCache entry
|
||||
* @property uuid
|
||||
* @public
|
||||
* @type {String}
|
||||
*/
|
||||
this.uuid = uuid;
|
||||
|
||||
/**
|
||||
* The distance from the top left to the bottom-right of this Frame.
|
||||
* @type {number}
|
||||
*/
|
||||
* center X position within the image to cut from.
|
||||
* @property centerX
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.centerX = Math.floor(width / 2);
|
||||
|
||||
/**
|
||||
* center Y position within the image to cut from.
|
||||
* @property centerY
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
/**
|
||||
* The distance from the top left to the bottom-right of this Frame.
|
||||
* @property distance
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
|
||||
/**
|
||||
* Rotated? (not yet implemented)
|
||||
*/
|
||||
* Rotated? (not yet implemented)
|
||||
* @property rotated
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
* @default false
|
||||
*/
|
||||
this.rotated = false;
|
||||
|
||||
/**
|
||||
* Either cw or ccw, rotation is always 90 degrees.
|
||||
*/
|
||||
* Either cw or ccw, rotation is always 90 degrees.
|
||||
* @property rotationDirection
|
||||
* @public
|
||||
* @type {String}
|
||||
* @default "cw"
|
||||
*/
|
||||
this.rotationDirection = 'cw';
|
||||
|
||||
/**
|
||||
* Was it trimmed when packed?
|
||||
* @type {bool}
|
||||
*/
|
||||
* Was it trimmed when packed?
|
||||
* @property trimmed
|
||||
* @public
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.trimmed = false;
|
||||
|
||||
/**
|
||||
* Width of the original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* Width of the original sprite.
|
||||
* @property sourceSizeW
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.sourceSizeW = width;
|
||||
|
||||
/**
|
||||
* Height of the original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* Height of the original sprite.
|
||||
* @property sourceSizeH
|
||||
* @public
|
||||
* @type {Number}
|
||||
*/
|
||||
this.sourceSizeH = height;
|
||||
|
||||
/**
|
||||
* X position of the trimmed sprite inside original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* X position of the trimmed sprite inside original sprite.
|
||||
* @property spriteSourceSizeX
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
this.spriteSourceSizeX = 0;
|
||||
|
||||
/**
|
||||
* Y position of the trimmed sprite inside original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* Y position of the trimmed sprite inside original sprite.
|
||||
* @property spriteSourceSizeY
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
this.spriteSourceSizeY = 0;
|
||||
|
||||
/**
|
||||
* Width of the trimmed sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* Width of the trimmed sprite.
|
||||
* @property spriteSourceSizeW
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
this.spriteSourceSizeW = 0;
|
||||
|
||||
/**
|
||||
* Height of the trimmed sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
* Height of the trimmed sprite.
|
||||
* @property spriteSourceSizeH
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
*/
|
||||
this.spriteSourceSizeH = 0;
|
||||
|
||||
};
|
||||
@@ -125,14 +183,16 @@ Phaser.Animation.Frame = function (x, y, width, height, name, uuid) {
|
||||
Phaser.Animation.Frame.prototype = {
|
||||
|
||||
/**
|
||||
* Set trim of the frame.
|
||||
* @param trimmed {bool} Whether this frame trimmed or not.
|
||||
* @param actualWidth {number} Actual width of this frame.
|
||||
* @param actualHeight {number} Actual height of this frame.
|
||||
* @param destX {number} Destination x position.
|
||||
* @param destY {number} Destination y position.
|
||||
* @param destWidth {number} Destination draw width.
|
||||
* @param destHeight {number} Destination draw height.
|
||||
* 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.
|
||||
*/
|
||||
setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
||||
|
||||
|
||||
+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;
|
||||
}
|
||||
|
||||
+44
-25
@@ -1,23 +1,25 @@
|
||||
/**
|
||||
* Animation Parser
|
||||
*
|
||||
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
|
||||
*
|
||||
* @package Phaser.Animation.Parser
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @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
|
||||
*/
|
||||
|
||||
Phaser.Animation.Parser = {
|
||||
|
||||
/**
|
||||
* Parse a sprite sheet from asset data.
|
||||
* @param key {string} Asset key for the sprite sheet data.
|
||||
* @param frameWidth {number} Width of animation frame.
|
||||
* @param frameHeight {number} Height of animation frame.
|
||||
* @param frameMax {number} Number of animation frames.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
/**
|
||||
* 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.
|
||||
* @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) {
|
||||
|
||||
// How big is our image?
|
||||
@@ -55,7 +57,7 @@ Phaser.Animation.Parser = {
|
||||
{
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
data.addFrame(new Phaser.Animation.Frame(x, y, frameWidth, frameHeight, '', uuid));
|
||||
data.addFrame(new Phaser.Animation.Frame(i, x, y, frameWidth, frameHeight, '', uuid));
|
||||
|
||||
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[key], {
|
||||
x: x,
|
||||
@@ -78,9 +80,13 @@ Phaser.Animation.Parser = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from json texture atlas in Array format.
|
||||
* @param json {object} Json data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
* 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.
|
||||
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONData: function (game, json, cacheKey) {
|
||||
|
||||
@@ -104,6 +110,7 @@ Phaser.Animation.Parser = {
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Animation.Frame(
|
||||
i,
|
||||
frames[i].frame.x,
|
||||
frames[i].frame.y,
|
||||
frames[i].frame.w,
|
||||
@@ -141,9 +148,13 @@ Phaser.Animation.Parser = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from json texture atlas in Hash format.
|
||||
* @param json {object} Json data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
* 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.
|
||||
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONDataHash: function (game, json, cacheKey) {
|
||||
|
||||
@@ -161,13 +172,14 @@ Phaser.Animation.Parser = {
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json['frames'];
|
||||
var newFrame;
|
||||
var i = 0;
|
||||
|
||||
for (var key in frames)
|
||||
{
|
||||
console.log(key);
|
||||
var uuid = game.rnd.uuid();
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Animation.Frame(
|
||||
i,
|
||||
frames[key].frame.x,
|
||||
frames[key].frame.y,
|
||||
frames[key].frame.w,
|
||||
@@ -198,6 +210,8 @@ Phaser.Animation.Parser = {
|
||||
PIXI.TextureCache[uuid].realSize = frames[key].spriteSourceSize;
|
||||
PIXI.TextureCache[uuid].trim.x = 0;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -205,9 +219,13 @@ Phaser.Animation.Parser = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from an XML file.
|
||||
* @param xml {object} XML data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
* 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.
|
||||
* @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
XMLData: function (game, xml, cacheKey) {
|
||||
|
||||
@@ -230,6 +248,7 @@ Phaser.Animation.Parser = {
|
||||
var frame = frames[i].attributes;
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Animation.Frame(
|
||||
i,
|
||||
frame.x.nodeValue,
|
||||
frame.y.nodeValue,
|
||||
frame.width.nodeValue,
|
||||
|
||||
@@ -361,8 +361,8 @@ Phaser.StateManager.prototype = {
|
||||
if (this._created == false && this.onCreateCallback)
|
||||
{
|
||||
// console.log('Create callback found');
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
this._created = true;
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -19,10 +19,13 @@ Phaser.BitmapText = function (game, x, y, text, style) {
|
||||
|
||||
PIXI.BitmapText.call(this, text, style);
|
||||
|
||||
this.type = Phaser.BITMAPTEXT;
|
||||
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
// Replaces the PIXI.Point with a slightly more flexible one
|
||||
this.anchor = new Phaser.Point();
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
// Influence of camera movement upon the position
|
||||
@@ -51,11 +54,10 @@ Phaser.BitmapText = function (game, x, y, text, style) {
|
||||
|
||||
};
|
||||
|
||||
Phaser.BitmapText.prototype = Phaser.Utils.extend(true, PIXI.BitmapText.prototype);
|
||||
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
|
||||
// Phaser.BitmapText.prototype = Phaser.Utils.extend(true, PIXI.BitmapText.prototype);
|
||||
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
|
||||
|
||||
// Add our own custom methods
|
||||
|
||||
/**
|
||||
* Automatically called by World.update
|
||||
*/
|
||||
|
||||
+100
-19
@@ -5,31 +5,112 @@ Phaser.Text = function (game, x, y, text, style) {
|
||||
text = text || '';
|
||||
style = style || '';
|
||||
|
||||
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
|
||||
this.exists = true;
|
||||
|
||||
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
|
||||
this.alive = true;
|
||||
|
||||
this.group = null;
|
||||
|
||||
this.name = '';
|
||||
|
||||
this.game = game;
|
||||
|
||||
PIXI.Text.call(this, text, style);
|
||||
|
||||
/*
|
||||
this.canvas = document.createElement("canvas");
|
||||
this.context = this.canvas.getContext("2d");
|
||||
|
||||
var canvasID = game.rnd.uuid();
|
||||
|
||||
PIXI.TextureCache[canvasID] = new PIXI.Texture(new PIXI.BaseTexture(this.canvas));
|
||||
|
||||
Phaser.Sprite.call(this, game, x, y, canvasID);
|
||||
|
||||
this.type = Phaser.TEXT;
|
||||
|
||||
this.setText(text);
|
||||
this.setStyle(style);
|
||||
|
||||
this.updateText();
|
||||
this.dirty = false;
|
||||
*/
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
// Replaces the PIXI.Point with a slightly more flexible one
|
||||
this.anchor = new Phaser.Point();
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
// Influence of camera movement upon the position
|
||||
this.scrollFactor = new Phaser.Point(1, 1);
|
||||
|
||||
// A mini cache for storing all of the calculated values
|
||||
this._cache = {
|
||||
|
||||
dirty: false,
|
||||
|
||||
// Transform cache
|
||||
a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1,
|
||||
|
||||
// The previous calculated position inc. camera x/y and scrollFactor
|
||||
x: -1, y: -1,
|
||||
|
||||
// The actual scale values based on the worldTransform
|
||||
scaleX: 1, scaleY: 1
|
||||
|
||||
};
|
||||
|
||||
this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
|
||||
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
this.renderable = true;
|
||||
|
||||
};
|
||||
|
||||
// Phaser.Text.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Text.prototype);
|
||||
Phaser.Text.prototype = Phaser.Utils.extend(true, PIXI.Text.prototype);
|
||||
Phaser.Text.prototype = Object.create(PIXI.Text.prototype);
|
||||
Phaser.Text.prototype.constructor = Phaser.Text;
|
||||
|
||||
// Add our own custom methods
|
||||
// Automatically called by World.update
|
||||
Phaser.Text.prototype.update = function() {
|
||||
|
||||
if (!this.exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._cache.dirty = false;
|
||||
|
||||
this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
|
||||
this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
|
||||
{
|
||||
this.position.x = this._cache.x;
|
||||
this.position.y = this._cache.y;
|
||||
this._cache.dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.defineProperty(Phaser.Text.prototype, 'angle', {
|
||||
|
||||
get: function() {
|
||||
return Phaser.Math.radToDeg(this.rotation);
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.rotation = Phaser.Math.degToRad(value);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Text.prototype, 'x', {
|
||||
|
||||
get: function() {
|
||||
return this.position.x;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.position.x = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Text.prototype, 'y', {
|
||||
|
||||
get: function() {
|
||||
return this.position.y;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
this.position.y = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -69,6 +69,9 @@ Phaser.Utils = {
|
||||
|
||||
// deep, target, objects to copy to the target object
|
||||
// This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/)
|
||||
// deep (boolean)
|
||||
// target (object to add to)
|
||||
// objects ... (objects to recurse and copy from)
|
||||
extend: function () {
|
||||
|
||||
var options, name, src, copy, copyIsArray, clone,
|
||||
|
||||
Reference in New Issue
Block a user