2013-08-30 03:20:14 +00:00
|
|
|
/**
|
2013-09-17 15:28:59 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-10-01 15:15:45 +00:00
|
|
|
* The Animation Manager is used to add, play and update Phaser Animations.
|
2013-09-17 15:28:59 +00:00
|
|
|
* Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance.
|
2013-08-30 03:20:14 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.AnimationManager
|
2013-09-17 15:28:59 +00:00
|
|
|
* @constructor
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {Phaser.Sprite} sprite - A reference to the Game Object that owns this AnimationManager.
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
Phaser.AnimationManager = function (sprite) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.sprite = sprite;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.game = sprite.game;
|
|
|
|
|
|
|
|
/**
|
2015-05-18 11:54:00 +00:00
|
|
|
* The currently displayed Frame of animation, if any.
|
|
|
|
* This property is only set once an Animation starts playing. Until that point it remains set as `null`.
|
|
|
|
*
|
|
|
|
* @property {Phaser.Frame} currentFrame
|
2013-11-25 03:13:04 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.currentFrame = null;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-04-28 22:35:08 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Animation} currentAnim - The currently displayed animation, if any.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.currentAnim = null;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.updateIfVisible = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} isLoaded - Set to true once animation data has been loaded.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.isLoaded = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this._frameData = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {object} _anims - An internal object that stores all of the Animation instances.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._anims = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {object} _outputFrames - An internal object to help avoid gc.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._outputFrames = [];
|
2013-09-10 19:40:34 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.AnimationManager.prototype = {
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* Loads FrameData into the internal temporary vars and resets the frame index to zero.
|
|
|
|
* This is called automatically when a new Sprite is created.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.AnimationManager#loadFrameData
|
2013-09-17 15:28:59 +00:00
|
|
|
* @private
|
2013-10-03 01:38:35 +00:00
|
|
|
* @param {Phaser.FrameData} frameData - The FrameData set to load.
|
2014-06-10 10:21:07 +00:00
|
|
|
* @param {string|number} frame - The frame to default to.
|
2014-07-10 13:46:28 +00:00
|
|
|
* @return {boolean} Returns `true` if the frame data was loaded successfully, otherwise `false`
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2014-06-10 10:21:07 +00:00
|
|
|
loadFrameData: function (frameData, frame) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (frameData === undefined)
|
2014-10-01 04:21:30 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-15 23:55:12 +00:00
|
|
|
if (this.isLoaded)
|
|
|
|
{
|
|
|
|
// We need to update the frameData that the animations are using
|
|
|
|
for (var anim in this._anims)
|
|
|
|
{
|
|
|
|
this._anims[anim].updateFrameData(frameData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this._frameData = frameData;
|
2014-06-10 10:21:07 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (frame === undefined || frame === null)
|
2014-09-02 20:03:16 +00:00
|
|
|
{
|
|
|
|
this.frame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (typeof frame === 'string')
|
|
|
|
{
|
|
|
|
this.frameName = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isLoaded = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 Phaser.AnimationManager#copyFrameData
|
|
|
|
* @private
|
|
|
|
* @param {Phaser.FrameData} frameData - The FrameData set to load.
|
|
|
|
* @param {string|number} frame - The frame to default to.
|
|
|
|
* @return {boolean} Returns `true` if the frame data was loaded successfully, otherwise `false`
|
|
|
|
*/
|
|
|
|
copyFrameData: function (frameData, frame) {
|
|
|
|
|
|
|
|
this._frameData = frameData.clone();
|
|
|
|
|
|
|
|
if (this.isLoaded)
|
|
|
|
{
|
|
|
|
// We need to update the frameData that the animations are using
|
|
|
|
for (var anim in this._anims)
|
|
|
|
{
|
|
|
|
this._anims[anim].updateFrameData(this._frameData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (frame === undefined || frame === null)
|
2014-06-10 10:21:07 +00:00
|
|
|
{
|
|
|
|
this.frame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (typeof frame === 'string')
|
|
|
|
{
|
|
|
|
this.frameName = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.isLoaded = true;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2014-07-22 08:42:47 +00:00
|
|
|
return true;
|
2013-11-25 03:13:04 +00:00
|
|
|
},
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.AnimationManager#add
|
2013-11-25 03:13:04 +00:00
|
|
|
* @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] - 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) {
|
|
|
|
|
2014-02-26 01:32:38 +00:00
|
|
|
frames = frames || [];
|
2013-11-25 03:13:04 +00:00
|
|
|
frameRate = frameRate || 60;
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (loop === undefined) { loop = false; }
|
2013-11-25 03:13:04 +00:00
|
|
|
|
|
|
|
// If they didn't set the useNumericIndex then let's at least try and guess it
|
2015-07-22 09:37:15 +00:00
|
|
|
if (useNumericIndex === undefined)
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
|
|
|
if (frames && typeof frames[0] === 'number')
|
|
|
|
{
|
|
|
|
useNumericIndex = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
useNumericIndex = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:54:00 +00:00
|
|
|
this._outputFrames = [];
|
2013-11-25 03:13:04 +00:00
|
|
|
|
|
|
|
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
|
|
|
|
|
|
|
|
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
|
2014-06-06 03:12:16 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.currentAnim = this._anims[name];
|
2015-05-18 11:54:00 +00:00
|
|
|
|
2015-04-21 04:11:19 +00:00
|
|
|
if (this.sprite.tilingTexture)
|
|
|
|
{
|
|
|
|
this.sprite.refreshTexture = true;
|
|
|
|
}
|
2013-11-25 03:13:04 +00:00
|
|
|
|
|
|
|
return this._anims[name];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the frames in the given array are valid and exist.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.AnimationManager#validateFrames
|
2013-11-25 03:13:04 +00:00
|
|
|
* @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) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (useNumericIndex === undefined) { useNumericIndex = true; }
|
2013-11-25 03:13:04 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < frames.length; i++)
|
|
|
|
{
|
|
|
|
if (useNumericIndex === true)
|
|
|
|
{
|
|
|
|
if (frames[i] > this._frameData.total)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this._frameData.checkFrameName(frames[i]) === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-03-25 03:59:36 +00:00
|
|
|
* Play an animation based on the given key. The animation should previously have been added via `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.
|
2014-03-23 07:59:28 +00:00
|
|
|
*
|
2013-11-25 03:13:04 +00:00
|
|
|
* @method Phaser.AnimationManager#play
|
|
|
|
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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.
|
2013-10-09 12:36:57 +00:00
|
|
|
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
|
|
|
|
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
|
2013-09-17 15:28:59 +00:00
|
|
|
* @return {Phaser.Animation} A reference to playing Animation instance.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
|
|
|
play: function (name, frameRate, loop, killOnComplete) {
|
|
|
|
|
|
|
|
if (this._anims[name])
|
|
|
|
{
|
2014-04-14 22:29:09 +00:00
|
|
|
if (this.currentAnim === this._anims[name])
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
|
|
|
if (this.currentAnim.isPlaying === false)
|
|
|
|
{
|
|
|
|
this.currentAnim.paused = false;
|
|
|
|
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
|
|
|
}
|
2015-05-18 11:54:00 +00:00
|
|
|
|
2014-06-15 04:59:57 +00:00
|
|
|
return this.currentAnim;
|
2013-11-25 03:13:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-04-14 22:29:09 +00:00
|
|
|
if (this.currentAnim && this.currentAnim.isPlaying)
|
|
|
|
{
|
|
|
|
this.currentAnim.stop();
|
|
|
|
}
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.currentAnim = this._anims[name];
|
|
|
|
this.currentAnim.paused = false;
|
2014-07-17 03:05:27 +00:00
|
|
|
this.currentFrame = this.currentAnim.currentFrame;
|
2013-11-25 03:13:04 +00:00
|
|
|
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 Phaser.AnimationManager#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) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (resetFrame === undefined) { resetFrame = false; }
|
2013-11-25 03:13:04 +00:00
|
|
|
|
2016-01-17 20:34:57 +00:00
|
|
|
if (this.currentAnim && (typeof name !== 'string' || name === this.currentAnim.name))
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
2016-01-17 20:34:57 +00:00
|
|
|
this.currentAnim.stop(resetFrame);
|
2013-11-25 03:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
|
2014-03-23 07:59:28 +00:00
|
|
|
*
|
2013-11-25 03:13:04 +00:00
|
|
|
* @method Phaser.AnimationManager#update
|
|
|
|
* @protected
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {boolean} True if a new animation frame has been set, otherwise false.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
|
|
|
update: function () {
|
|
|
|
|
2014-02-24 23:06:45 +00:00
|
|
|
if (this.updateIfVisible && !this.sprite.visible)
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-17 06:00:55 +00:00
|
|
|
if (this.currentAnim && this.currentAnim.update())
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
|
|
|
this.currentFrame = this.currentAnim.currentFrame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-07-03 15:23:36 +00:00
|
|
|
/**
|
|
|
|
* Advances by the given number of frames in the current animation, taking the loop value into consideration.
|
|
|
|
*
|
|
|
|
* @method Phaser.AnimationManager#next
|
|
|
|
* @param {number} [quantity=1] - The number of frames to advance.
|
|
|
|
*/
|
|
|
|
next: function (quantity) {
|
|
|
|
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
this.currentAnim.next(quantity);
|
|
|
|
this.currentFrame = this.currentAnim.currentFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves backwards the given number of frames in the current animation, taking the loop value into consideration.
|
|
|
|
*
|
|
|
|
* @method Phaser.AnimationManager#previous
|
|
|
|
* @param {number} [quantity=1] - The number of frames to move back.
|
|
|
|
*/
|
|
|
|
previous: function (quantity) {
|
|
|
|
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
this.currentAnim.previous(quantity);
|
|
|
|
this.currentFrame = this.currentAnim.currentFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Returns an animation that was previously added by name.
|
|
|
|
*
|
|
|
|
* @method Phaser.AnimationManager#getAnimation
|
|
|
|
* @param {string} name - The name of the animation to be returned, e.g. "fire".
|
2014-02-05 16:54:35 +00:00
|
|
|
* @return {Phaser.Animation} The Animation instance, if found, otherwise null.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
|
|
|
getAnimation: function (name) {
|
2013-11-04 00:04:19 +00:00
|
|
|
|
2014-02-13 23:13:10 +00:00
|
|
|
if (typeof name === 'string')
|
2013-11-25 03:13:04 +00:00
|
|
|
{
|
|
|
|
if (this._anims[name])
|
|
|
|
{
|
|
|
|
return this._anims[name];
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 00:04:19 +00:00
|
|
|
|
2014-02-05 16:54:35 +00:00
|
|
|
return null;
|
2013-11-04 00:04:19 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
},
|
2013-11-04 00:04:19 +00:00
|
|
|
|
2013-10-18 14:12:32 +00:00
|
|
|
/**
|
|
|
|
* Refreshes the current frame data back to the parent Sprite and also resets the texture data.
|
|
|
|
*
|
|
|
|
* @method Phaser.AnimationManager#refreshFrame
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
refreshFrame: function () {
|
2013-10-18 14:12:32 +00:00
|
|
|
|
2015-04-21 16:01:24 +00:00
|
|
|
// TODO
|
* PIXI.Texture.fromImage, PIXI.BaseTexture.fromImage and PIXI.Sprite.fromImage have all been removed. They should never have actually been used, as they bypass the Phaser Loader, and don't factor in CORs or any other advanced loader settings.
* The PIXI.BaseTexture.imageUrl property has been removed, as it was never actually populated.
* The PIXI.BaseTexture._UID property has been removed, as it was never actually used internally.
* All references to PIXI.BaseTextureCache have been removed (primarily from BaseTexture.destroy and Texture.destroy), as the BaseTextureCache was never used internally by Phaser, or by our custom version of Pixi.
* PIXI.TextureCache has been removed. It was only ever used by the __default and __missing images that Phaser generates on start-up. It wasn't used internally by Phaser anywhere else, and the only references Pixi has to it have all been removed. If you need it in your own game, please refactor it to avoid it, or re-create the object on the PIXI global object.
* Canvases created by `BaseTexture.fromCanvas` no longer have the `_pixiId` property attached to them, as this was never used internally by Phaser or Pixi.
* PIXI.BaseTexture.updateSourceImage is now deprecated. Please use `Sprite.loadTexture` instead.
* The property PIXI.BaseTextureCacheIdGenerator has been removed, as it is no longer used internally by Phaser or Pixi.
* PIXI.Texture.addTextureToCache has been removed. The PIXI Texture Cache was never actually used by Phaser, and was leading to complications internally.
* PIXI.Texture.removeTextureFromCache has been removed. The PIXI Texture Cache was never actually used by Phaser, and was leading to complications internally.
* PIXI.Texture.fromFrame and PIXI.Sprite.fromFrame have been removed. They relied on the PIXI Texture Cache, which was never actually used by Phaser, and was never used internally by Pixi either.
* The property PIXI.TextureCacheIdGenerator has been removed, as it was not used internally.
* The property PIXI.FrameCache has been removed, as it was not used internally.
2016-07-06 20:47:27 +00:00
|
|
|
// this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
2013-10-18 14:12:32 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
},
|
2013-10-18 14:12:32 +00:00
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2014-04-14 21:53:05 +00:00
|
|
|
* Destroys all references this AnimationManager contains.
|
|
|
|
* Iterates through the list of animations stored in this manager and calls destroy on each of them.
|
2013-09-17 15:28:59 +00:00
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.AnimationManager#destroy
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
|
|
|
destroy: function () {
|
|
|
|
|
2014-04-14 21:53:05 +00:00
|
|
|
var anim = null;
|
|
|
|
|
|
|
|
for (var anim in this._anims)
|
|
|
|
{
|
|
|
|
if (this._anims.hasOwnProperty(anim))
|
|
|
|
{
|
|
|
|
this._anims[anim].destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
this._anims = {};
|
2014-12-15 09:42:13 +00:00
|
|
|
this._outputFrames = [];
|
2013-08-30 03:20:14 +00:00
|
|
|
this._frameData = null;
|
|
|
|
this.currentAnim = null;
|
|
|
|
this.currentFrame = null;
|
2014-12-15 09:42:13 +00:00
|
|
|
this.sprite = null;
|
|
|
|
this.game = null;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
Phaser.AnimationManager.prototype.constructor = Phaser.AnimationManager;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.AnimationManager#frameData
|
2013-10-03 01:38:35 +00:00
|
|
|
* @property {Phaser.FrameData} frameData - The current animations FrameData.
|
2013-10-02 11:11:22 +00:00
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameData', {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._frameData;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.AnimationManager#frameTotal
|
|
|
|
* @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
|
2013-10-02 11:11:22 +00:00
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
get: function () {
|
|
|
|
|
2014-07-22 08:42:47 +00:00
|
|
|
return this._frameData.total;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.AnimationManager#paused
|
|
|
|
* @property {boolean} paused - Gets and sets the paused state of the current animation.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'paused', {
|
2013-09-30 10:15:50 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.currentAnim.isPaused;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
this.currentAnim.paused = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-10-09 13:06:13 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.AnimationManager#name
|
|
|
|
* @property {string} name - Gets the current animation name, if set.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'name', {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
return this.currentAnim.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.AnimationManager#frame
|
|
|
|
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.currentFrame)
|
|
|
|
{
|
2015-01-08 01:28:13 +00:00
|
|
|
return this.currentFrame.index;
|
2013-11-25 03:13:04 +00:00
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2014-12-03 20:59:44 +00:00
|
|
|
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null)
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
|
|
|
this.currentFrame = this._frameData.getFrame(value);
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-10 19:06:03 +00:00
|
|
|
if (this.currentFrame)
|
2014-02-13 23:13:10 +00:00
|
|
|
{
|
2014-06-06 03:12:16 +00:00
|
|
|
this.sprite.setFrame(this.currentFrame);
|
2014-02-13 23:13:10 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.AnimationManager#frameName
|
|
|
|
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.currentFrame)
|
|
|
|
{
|
|
|
|
return this.currentFrame.name;
|
|
|
|
}
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2015-04-13 10:58:26 +00:00
|
|
|
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null)
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
|
|
|
this.currentFrame = this._frameData.getFrameByName(value);
|
2014-03-10 19:06:03 +00:00
|
|
|
|
|
|
|
if (this.currentFrame)
|
2014-02-13 23:13:10 +00:00
|
|
|
{
|
2014-03-10 19:06:03 +00:00
|
|
|
this._frameIndex = this.currentFrame.index;
|
2014-06-10 22:37:33 +00:00
|
|
|
|
2014-06-06 03:12:16 +00:00
|
|
|
this.sprite.setFrame(this.currentFrame);
|
2014-02-13 23:13:10 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-25 03:13:04 +00:00
|
|
|
console.warn('Cannot set frameName: ' + value);
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
});
|