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-08-30 03:20:14 +00:00
|
|
|
* An Animation instance contains a single animation and the controls to play it.
|
2016-05-26 23:24:23 +00:00
|
|
|
*
|
2013-09-17 15:28:59 +00:00
|
|
|
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
|
2013-08-30 03:20:14 +00:00
|
|
|
*
|
2013-09-19 22:47:50 +00:00
|
|
|
* @class Phaser.Animation
|
2013-09-17 15:28:59 +00:00
|
|
|
* @constructor
|
2013-09-19 22:47:50 +00:00
|
|
|
* @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.
|
2013-10-03 01:38:35 +00:00
|
|
|
* @param {Phaser.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
|
2014-09-16 16:35:08 +00:00
|
|
|
* @param {number[]|string[]} frames - An array of numbers or strings indicating which frames to play in which order.
|
2014-10-10 13:49:01 +00:00
|
|
|
* @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.
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2014-10-10 13:49:01 +00:00
|
|
|
Phaser.Animation = function (game, parent, name, frameData, frames, frameRate, loop) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (loop === undefined) { loop = false; }
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this.game = game;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {Phaser.Sprite} _parent - A reference to the parent Sprite that owns this Animation.
|
2013-09-17 15:28:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this._parent = parent;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {Phaser.FrameData} _frameData - The FrameData the Animation uses.
|
2013-09-17 15:28:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._frameData = frameData;
|
|
|
|
|
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {string} name - The user defined name given to this Animation.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
/**
|
2013-12-27 00:26:21 +00:00
|
|
|
* @property {array} _frames
|
2013-09-17 15:28:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this._frames = [];
|
2013-09-19 22:47:50 +00:00
|
|
|
this._frames = this._frames.concat(frames);
|
2013-09-17 15:28:59 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-10 13:49:01 +00:00
|
|
|
* @property {number} delay - The delay in ms between each frame of the Animation, based on the given frameRate.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2014-10-10 13:49:01 +00:00
|
|
|
this.delay = 1000 / frameRate;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-03 16:05:55 +00:00
|
|
|
* @property {boolean} loop - The loop state of the Animation.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2014-03-03 16:05:55 +00:00
|
|
|
this.loop = loop;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} loopCount - The number of times the animation has looped since it was last started.
|
|
|
|
*/
|
|
|
|
this.loopCount = 0;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
2013-10-09 12:36:57 +00:00
|
|
|
/**
|
2013-12-27 00:26:21 +00:00
|
|
|
* @property {boolean} killOnComplete - Should the parent of this Animation be killed when the animation completes?
|
|
|
|
* @default
|
2013-10-09 12:36:57 +00:00
|
|
|
*/
|
|
|
|
this.killOnComplete = false;
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
|
|
|
|
* @default
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this.isFinished = false;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {boolean} isPlaying - The playing state of the Animation. Set to false once playback completes, true during playback.
|
|
|
|
* @default
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this.isPlaying = false;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} isPaused - The paused state of the Animation.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.isPaused = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} _pauseStartTime - The time the animation paused.
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this._pauseStartTime = 0;
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-09-19 22:47:50 +00:00
|
|
|
* @property {number} _frameIndex
|
2013-09-17 15:28:59 +00:00
|
|
|
* @private
|
2013-09-19 22:47:50 +00:00
|
|
|
* @default
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this._frameIndex = 0;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {number} _frameDiff
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-24 14:28:29 +00:00
|
|
|
this._frameDiff = 0;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} _frameSkip
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-24 14:28:29 +00:00
|
|
|
this._frameSkip = 1;
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2013-10-03 01:38:35 +00:00
|
|
|
* @property {Phaser.Frame} currentFrame - The currently displayed frame of the Animation.
|
2013-09-17 15:28:59 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
2014-02-24 23:06:45 +00:00
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onStart - This event is dispatched when this Animation starts playback.
|
|
|
|
*/
|
|
|
|
this.onStart = new Phaser.Signal();
|
|
|
|
|
2014-08-29 13:30:44 +00:00
|
|
|
/**
|
2016-05-26 23:24:23 +00:00
|
|
|
* This event is dispatched when the Animation changes frame.
|
2015-07-14 12:47:25 +00:00
|
|
|
* By default this event is disabled due to its intensive nature. Enable it with: `Animation.enableUpdate = true`.
|
2016-02-02 23:04:54 +00:00
|
|
|
* Note that the event is only dispatched with the current frame. In a low-FPS environment Animations
|
2016-05-26 23:24:23 +00:00
|
|
|
* will automatically frame-skip to try and claw back time, so do not base your code on expecting to
|
2016-02-02 23:04:54 +00:00
|
|
|
* receive a perfectly sequential set of frames from this event.
|
2015-07-14 12:47:25 +00:00
|
|
|
* @property {Phaser.Signal|null} onUpdate
|
2014-08-29 13:30:44 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.onUpdate = null;
|
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
/**
|
2015-08-31 09:57:54 +00:00
|
|
|
* @property {Phaser.Signal} onComplete - This event is dispatched when this Animation completes playback. If the animation is set to loop this is never fired, listen for onLoop instead.
|
2014-03-03 16:05:55 +00:00
|
|
|
*/
|
|
|
|
this.onComplete = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onLoop - This event is dispatched when this Animation loops.
|
|
|
|
*/
|
|
|
|
this.onLoop = new Phaser.Signal();
|
|
|
|
|
2016-05-26 23:24:23 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} isReversed - Indicates if the animation will play backwards.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.isReversed = false;
|
|
|
|
|
2014-02-24 23:06:45 +00:00
|
|
|
// Set-up some event listeners
|
|
|
|
this.game.onPause.add(this.onPause, this);
|
|
|
|
this.game.onResume.add(this.onResume, this);
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Animation.prototype = {
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* Plays this animation.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation#play
|
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-10-01 12:54:29 +00:00
|
|
|
* @return {Phaser.Animation} - A reference to this Animation instance.
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2013-10-09 12:36:57 +00:00
|
|
|
play: function (frameRate, loop, killOnComplete) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
if (typeof frameRate === 'number')
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
2013-09-27 08:57:08 +00:00
|
|
|
// If they set a new frame rate then use it, otherwise use the one set on creation
|
2013-09-18 05:41:41 +00:00
|
|
|
this.delay = 1000 / frameRate;
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
if (typeof loop === 'boolean')
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
2013-09-27 08:57:08 +00:00
|
|
|
// If they set a new loop value then use it, otherwise use the one set on creation
|
2014-03-03 16:05:55 +00:00
|
|
|
this.loop = loop;
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 12:36:57 +00:00
|
|
|
if (typeof killOnComplete !== 'undefined')
|
|
|
|
{
|
|
|
|
// Remove the parent sprite once the animation has finished?
|
|
|
|
this.killOnComplete = killOnComplete;
|
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
this.isPlaying = true;
|
|
|
|
this.isFinished = false;
|
2013-10-28 23:29:04 +00:00
|
|
|
this.paused = false;
|
2014-03-03 16:05:55 +00:00
|
|
|
this.loopCount = 0;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeLastFrame = this.game.time.time;
|
|
|
|
this._timeNextFrame = this.game.time.time + this.delay;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2016-05-27 14:43:36 +00:00
|
|
|
this._frameIndex = this.isReversed ? this._frames.length - 1 : 0;
|
2015-05-18 11:54:00 +00:00
|
|
|
this.updateCurrentFrame(false, true);
|
2014-02-13 23:13:10 +00:00
|
|
|
|
2014-12-01 03:49:15 +00:00
|
|
|
this._parent.events.onAnimationStart$dispatch(this._parent, this);
|
2014-06-10 22:37:33 +00:00
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
this.onStart.dispatch(this._parent, this);
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-03-25 03:59:36 +00:00
|
|
|
this._parent.animations.currentAnim = this;
|
|
|
|
this._parent.animations.currentFrame = this.currentFrame;
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* Sets this animation back to the first frame and restarts the animation.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation#restart
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
|
|
|
restart: function () {
|
|
|
|
|
|
|
|
this.isPlaying = true;
|
|
|
|
this.isFinished = false;
|
2013-10-28 23:29:04 +00:00
|
|
|
this.paused = false;
|
2014-03-03 16:05:55 +00:00
|
|
|
this.loopCount = 0;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeLastFrame = this.game.time.time;
|
|
|
|
this._timeNextFrame = this.game.time.time + this.delay;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
this._frameIndex = 0;
|
|
|
|
|
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
|
|
|
2014-06-10 22:37:33 +00:00
|
|
|
this._parent.setFrame(this.currentFrame);
|
|
|
|
|
2015-03-25 03:59:36 +00:00
|
|
|
this._parent.animations.currentAnim = this;
|
|
|
|
this._parent.animations.currentFrame = this.currentFrame;
|
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
this.onStart.dispatch(this._parent, this);
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
},
|
|
|
|
|
2016-05-27 14:48:06 +00:00
|
|
|
/**
|
|
|
|
* Reverses the animation direction
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#reverse
|
|
|
|
* */
|
|
|
|
reverse: function () {
|
|
|
|
this.reversed = !this.reversed;
|
|
|
|
},
|
|
|
|
|
2016-05-27 14:58:54 +00:00
|
|
|
/**
|
|
|
|
* Reverses the animation direction for the current/next animation only
|
|
|
|
* Once the onComplete event is called this method will be called again and revert
|
|
|
|
* the reversed state.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#reverseOnce
|
|
|
|
* */
|
|
|
|
reverseOnce: function () {
|
|
|
|
this.reverse();
|
|
|
|
|
|
|
|
this.onComplete.addOnce(this.reverse.bind(this))
|
|
|
|
},
|
|
|
|
|
2014-04-28 22:35:08 +00:00
|
|
|
/**
|
|
|
|
* Sets this animations playback to a given frame with the given ID.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#setFrame
|
|
|
|
* @param {string|number} [frameId] - The identifier of the frame to set. Can be the name of the frame, the sprite index of the frame, or the animation-local frame index.
|
|
|
|
* @param {boolean} [useLocalFrameIndex=false] - If you provide a number for frameId, should it use the numeric indexes of the frameData, or the 0-indexed frame index local to the animation.
|
|
|
|
*/
|
|
|
|
setFrame: function(frameId, useLocalFrameIndex) {
|
|
|
|
|
|
|
|
var frameIndex;
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (useLocalFrameIndex === undefined)
|
2014-04-28 22:35:08 +00:00
|
|
|
{
|
|
|
|
useLocalFrameIndex = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the index to the desired frame.
|
|
|
|
if (typeof frameId === "string")
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this._frames.length; i++)
|
|
|
|
{
|
|
|
|
if (this._frameData.getFrame(this._frames[i]).name === frameId)
|
|
|
|
{
|
|
|
|
frameIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (typeof frameId === "number")
|
|
|
|
{
|
|
|
|
if (useLocalFrameIndex)
|
|
|
|
{
|
|
|
|
frameIndex = frameId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this._frames.length; i++)
|
|
|
|
{
|
2014-11-02 11:02:32 +00:00
|
|
|
if (this._frames[i] === frameIndex)
|
2014-04-28 22:35:08 +00:00
|
|
|
{
|
|
|
|
frameIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frameIndex)
|
|
|
|
{
|
|
|
|
// Set the current frame index to the found index. Subtract 1 so that it animates to the desired frame on update.
|
|
|
|
this._frameIndex = frameIndex - 1;
|
|
|
|
|
|
|
|
// Make the animation update at next update
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeNextFrame = this.game.time.time;
|
2014-04-28 22:35:08 +00:00
|
|
|
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2014-03-03 16:05:55 +00:00
|
|
|
* If `dispatchComplete` is true it will dispatch the complete events, otherwise they'll be ignored.
|
2013-09-17 15:28:59 +00:00
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation#stop
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {boolean} [resetFrame=false] - If true after the animation stops the currentFrame value will be set to the first frame in this animation.
|
2014-03-03 16:05:55 +00:00
|
|
|
* @param {boolean} [dispatchComplete=false] - Dispatch the Animation.onComplete and parent.onAnimationComplete events?
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2014-03-03 16:05:55 +00:00
|
|
|
stop: function (resetFrame, dispatchComplete) {
|
2013-09-15 19:45:00 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (resetFrame === undefined) { resetFrame = false; }
|
|
|
|
if (dispatchComplete === undefined) { dispatchComplete = false; }
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
this.isPlaying = false;
|
|
|
|
this.isFinished = true;
|
2013-10-28 23:29:04 +00:00
|
|
|
this.paused = false;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-15 19:45:00 +00:00
|
|
|
if (resetFrame)
|
|
|
|
{
|
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[0]);
|
2014-06-10 22:37:33 +00:00
|
|
|
this._parent.setFrame(this.currentFrame);
|
2013-09-15 19:45:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
if (dispatchComplete)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
2014-03-03 16:05:55 +00:00
|
|
|
this.onComplete.dispatch(this._parent, this);
|
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
},
|
|
|
|
|
2014-02-24 23:06:45 +00:00
|
|
|
/**
|
|
|
|
* Called when the Game enters a paused state.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#onPause
|
|
|
|
*/
|
|
|
|
onPause: function () {
|
|
|
|
|
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
2014-11-08 20:01:10 +00:00
|
|
|
this._frameDiff = this._timeNextFrame - this.game.time.time;
|
2014-02-24 23:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the Game resumes from a paused state.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#onResume
|
|
|
|
*/
|
|
|
|
onResume: function () {
|
|
|
|
|
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeNextFrame = this.game.time.time + this._frameDiff;
|
2014-02-24 23:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* Updates this animation. Called automatically by the AnimationManager.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation#update
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
|
|
|
update: function () {
|
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
if (this.isPaused)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
if (this.isPlaying && this.game.time.time >= this._timeNextFrame)
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
2013-09-24 14:28:29 +00:00
|
|
|
this._frameSkip = 1;
|
|
|
|
|
|
|
|
// Lagging?
|
2014-11-08 20:01:10 +00:00
|
|
|
this._frameDiff = this.game.time.time - this._timeNextFrame;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeLastFrame = this.game.time.time;
|
2013-09-24 14:28:29 +00:00
|
|
|
|
|
|
|
if (this._frameDiff > this.delay)
|
|
|
|
{
|
|
|
|
// We need to skip a frame, work out how many
|
|
|
|
this._frameSkip = Math.floor(this._frameDiff / this.delay);
|
|
|
|
this._frameDiff -= (this._frameSkip * this.delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And what's left now?
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeNextFrame = this.game.time.time + (this.delay - this._frameDiff);
|
2013-09-24 14:28:29 +00:00
|
|
|
|
2016-05-26 23:24:23 +00:00
|
|
|
if (this.isReversed){
|
|
|
|
this._frameIndex -= this._frameSkip;
|
|
|
|
}else{
|
|
|
|
this._frameIndex += this._frameSkip;
|
|
|
|
}
|
2013-09-24 14:28:29 +00:00
|
|
|
|
2016-05-26 23:24:23 +00:00
|
|
|
if (!this.isReversed && this._frameIndex >= this._frames.length || this.isReversed && this._frameIndex <= 0)
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
2014-03-03 16:05:55 +00:00
|
|
|
if (this.loop)
|
2013-08-30 03:20:14 +00:00
|
|
|
{
|
2015-03-22 23:46:15 +00:00
|
|
|
// Update current state before event callback
|
2016-05-26 23:24:23 +00:00
|
|
|
this._frameIndex = Math.abs(this._frameIndex) % this._frames.length;
|
|
|
|
|
|
|
|
if (this.isReversed){
|
|
|
|
this._frameIndex = this._frames.length - 1 - this._frameIndex;
|
|
|
|
}
|
|
|
|
|
2014-06-06 03:12:16 +00:00
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
2015-07-14 12:47:25 +00:00
|
|
|
|
|
|
|
// Instead of calling updateCurrentFrame we do it here instead
|
|
|
|
if (this.currentFrame)
|
|
|
|
{
|
|
|
|
this._parent.setFrame(this.currentFrame);
|
|
|
|
}
|
|
|
|
|
2014-03-03 16:05:55 +00:00
|
|
|
this.loopCount++;
|
2014-12-01 03:49:15 +00:00
|
|
|
this._parent.events.onAnimationLoop$dispatch(this._parent, this);
|
2014-03-03 16:05:55 +00:00
|
|
|
this.onLoop.dispatch(this._parent, this);
|
2015-07-14 12:47:25 +00:00
|
|
|
|
|
|
|
if (this.onUpdate)
|
|
|
|
{
|
|
|
|
this.onUpdate.dispatch(this, this.currentFrame);
|
|
|
|
|
|
|
|
// False if the animation was destroyed from within a callback
|
|
|
|
return !!this._frameData;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-03 16:05:55 +00:00
|
|
|
this.complete();
|
2015-03-24 23:16:56 +00:00
|
|
|
return false;
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 23:16:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.updateCurrentFrame(true);
|
|
|
|
}
|
2015-03-22 23:46:15 +00:00
|
|
|
}
|
2013-11-09 02:16:52 +00:00
|
|
|
|
2015-03-22 23:46:15 +00:00
|
|
|
return false;
|
2014-10-11 03:52:06 +00:00
|
|
|
|
2015-03-22 23:46:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the currentFrame per the _frameIndex, updates the display state,
|
|
|
|
* and triggers the update signal.
|
|
|
|
*
|
|
|
|
* Returns true if the current frame update was 'successful', false otherwise.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#updateCurrentFrame
|
2015-07-14 12:47:25 +00:00
|
|
|
* @private
|
2015-05-18 11:54:00 +00:00
|
|
|
* @param {boolean} signalUpdate - If true the `Animation.onUpdate` signal will be dispatched.
|
|
|
|
* @param {boolean} fromPlay - Was this call made from the playing of a new animation?
|
2015-07-14 12:47:25 +00:00
|
|
|
* @return {boolean} True if the current frame was updated, otherwise false.
|
2015-03-22 23:46:15 +00:00
|
|
|
*/
|
2015-05-18 11:54:00 +00:00
|
|
|
updateCurrentFrame: function (signalUpdate, fromPlay) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (fromPlay === undefined) { fromPlay = false; }
|
2015-03-22 23:46:15 +00:00
|
|
|
|
|
|
|
if (!this._frameData)
|
|
|
|
{
|
|
|
|
// The animation is already destroyed, probably from a callback
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-26 23:24:23 +00:00
|
|
|
|
2015-07-14 12:47:25 +00:00
|
|
|
// Previous index
|
|
|
|
var idx = this.currentFrame.index;
|
2015-03-22 23:46:15 +00:00
|
|
|
|
2015-07-14 12:47:25 +00:00
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
2015-03-22 23:46:15 +00:00
|
|
|
|
2015-07-14 12:47:25 +00:00
|
|
|
if (this.currentFrame && (fromPlay || (!fromPlay && idx !== this.currentFrame.index)))
|
2015-03-22 23:46:15 +00:00
|
|
|
{
|
2015-07-14 12:47:25 +00:00
|
|
|
this._parent.setFrame(this.currentFrame);
|
2015-03-22 23:46:15 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-03-22 23:46:15 +00:00
|
|
|
if (this.onUpdate && signalUpdate)
|
|
|
|
{
|
|
|
|
this.onUpdate.dispatch(this, this.currentFrame);
|
2015-04-21 04:11:19 +00:00
|
|
|
|
2015-03-22 23:46:15 +00:00
|
|
|
// False if the animation was destroyed from within a callback
|
|
|
|
return !!this._frameData;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-30 03:20:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-07-03 15:23:36 +00:00
|
|
|
/**
|
|
|
|
* Advances by the given number of frames in the Animation, taking the loop value into consideration.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#next
|
|
|
|
* @param {number} [quantity=1] - The number of frames to advance.
|
|
|
|
*/
|
|
|
|
next: function (quantity) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (quantity === undefined) { quantity = 1; }
|
2014-07-03 15:23:36 +00:00
|
|
|
|
|
|
|
var frame = this._frameIndex + quantity;
|
|
|
|
|
|
|
|
if (frame >= this._frames.length)
|
|
|
|
{
|
|
|
|
if (this.loop)
|
|
|
|
{
|
|
|
|
frame %= this._frames.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame = this._frames.length - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame !== this._frameIndex)
|
|
|
|
{
|
|
|
|
this._frameIndex = frame;
|
2015-03-22 23:46:15 +00:00
|
|
|
this.updateCurrentFrame(true);
|
2014-07-03 15:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves backwards the given number of frames in the Animation, taking the loop value into consideration.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#previous
|
|
|
|
* @param {number} [quantity=1] - The number of frames to move back.
|
|
|
|
*/
|
|
|
|
previous: function (quantity) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (quantity === undefined) { quantity = 1; }
|
2014-07-03 15:23:36 +00:00
|
|
|
|
|
|
|
var frame = this._frameIndex - quantity;
|
|
|
|
|
|
|
|
if (frame < 0)
|
|
|
|
{
|
|
|
|
if (this.loop)
|
|
|
|
{
|
|
|
|
frame = this._frames.length + frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame !== this._frameIndex)
|
|
|
|
{
|
|
|
|
this._frameIndex = frame;
|
2015-03-22 23:46:15 +00:00
|
|
|
this.updateCurrentFrame(true);
|
2014-07-03 15:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-07-15 23:55:12 +00:00
|
|
|
/**
|
|
|
|
* Changes the FrameData object this Animation is using.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animation#updateFrameData
|
|
|
|
* @param {Phaser.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
|
|
|
|
*/
|
|
|
|
updateFrameData: function (frameData) {
|
|
|
|
|
|
|
|
this._frameData = frameData;
|
2014-07-16 10:00:30 +00:00
|
|
|
this.currentFrame = this._frameData ? this._frameData.getFrame(this._frames[this._frameIndex % this._frames.length]) : null;
|
2014-07-15 23:55:12 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
|
|
|
* Cleans up this animation ready for deletion. Nulls all values and references.
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation#destroy
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
|
|
|
destroy: function () {
|
2014-06-05 01:33:13 +00:00
|
|
|
|
2015-03-22 23:46:15 +00:00
|
|
|
if (!this._frameData)
|
|
|
|
{
|
|
|
|
// Already destroyed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-17 11:16:24 +00:00
|
|
|
this.game.onPause.remove(this.onPause, this);
|
|
|
|
this.game.onResume.remove(this.onResume, this);
|
2014-10-11 03:52:06 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
this.game = null;
|
|
|
|
this._parent = null;
|
|
|
|
this._frames = null;
|
|
|
|
this._frameData = null;
|
|
|
|
this.currentFrame = null;
|
|
|
|
this.isPlaying = false;
|
|
|
|
|
2014-04-14 21:53:05 +00:00
|
|
|
this.onStart.dispose();
|
|
|
|
this.onLoop.dispose();
|
|
|
|
this.onComplete.dispose();
|
2014-03-03 16:05:55 +00:00
|
|
|
|
2014-08-29 13:30:44 +00:00
|
|
|
if (this.onUpdate)
|
|
|
|
{
|
|
|
|
this.onUpdate.dispose();
|
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
},
|
|
|
|
|
2013-09-17 15:28:59 +00:00
|
|
|
/**
|
2014-03-03 16:05:55 +00:00
|
|
|
* Called internally when the animation finishes playback.
|
|
|
|
* Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent and local onComplete event.
|
2013-09-17 15:28:59 +00:00
|
|
|
*
|
2014-03-03 16:05:55 +00:00
|
|
|
* @method Phaser.Animation#complete
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2014-03-03 16:05:55 +00:00
|
|
|
complete: function () {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-02-22 19:26:56 +00:00
|
|
|
this._frameIndex = this._frames.length - 1;
|
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
this.isPlaying = false;
|
|
|
|
this.isFinished = true;
|
2013-10-28 23:29:04 +00:00
|
|
|
this.paused = false;
|
2013-09-17 15:28:59 +00:00
|
|
|
|
2014-12-01 03:49:15 +00:00
|
|
|
this._parent.events.onAnimationComplete$dispatch(this._parent, this);
|
2014-03-03 16:05:55 +00:00
|
|
|
|
|
|
|
this.onComplete.dispatch(this._parent, this);
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-10-09 12:36:57 +00:00
|
|
|
if (this.killOnComplete)
|
|
|
|
{
|
|
|
|
this._parent.kill();
|
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
Phaser.Animation.prototype.constructor = Phaser.Animation;
|
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.Animation#paused
|
|
|
|
* @property {boolean} paused - Gets and sets the paused state of this Animation.
|
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'paused', {
|
2013-09-27 08:57:08 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.isPaused;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
this.isPaused = value;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
// Paused
|
2014-11-08 20:01:10 +00:00
|
|
|
this._pauseStartTime = this.game.time.time;
|
2013-09-27 08:57:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Un-paused
|
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
2014-11-08 20:01:10 +00:00
|
|
|
this._timeNextFrame = this.game.time.time + this.delay;
|
2013-09-27 08:57:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-05-26 23:24:23 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.Animation#reversed
|
|
|
|
* @property {boolean} reversed - Gets and sets the isReversed state of this Animation.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'reversed', {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.isReversed;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
this.isReversed = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.Animation#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-02 00:16:40 +00:00
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'frameTotal', {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._frames.length;
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-09-24 14:28:29 +00:00
|
|
|
/**
|
2013-10-02 00:16:40 +00:00
|
|
|
* @name Phaser.Animation#frame
|
|
|
|
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
|
|
|
|
*/
|
2013-11-24 12:51:20 +00:00
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'frame', {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
if (this.currentFrame !== null)
|
|
|
|
{
|
|
|
|
return this.currentFrame.index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this._frameIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2014-02-21 10:31:17 +00:00
|
|
|
this.currentFrame = this._frameData.getFrame(this._frames[value]);
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
if (this.currentFrame !== null)
|
|
|
|
{
|
|
|
|
this._frameIndex = value;
|
2014-06-06 03:12:16 +00:00
|
|
|
this._parent.setFrame(this.currentFrame);
|
2014-08-29 13:30:44 +00:00
|
|
|
|
|
|
|
if (this.onUpdate)
|
|
|
|
{
|
|
|
|
this.onUpdate.dispatch(this, this.currentFrame);
|
|
|
|
}
|
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-09-27 08:57:08 +00:00
|
|
|
|
2014-02-28 04:32:12 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.Animation#speed
|
2014-10-10 13:49:01 +00:00
|
|
|
* @property {number} speed - Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Minimum value is 1.
|
2014-02-28 04:32:12 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'speed', {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return Math.round(1000 / this.delay);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value >= 1)
|
|
|
|
{
|
|
|
|
this.delay = 1000 / value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-08-29 13:30:44 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.Animation#enableUpdate
|
|
|
|
* @property {boolean} enableUpdate - Gets or sets if this animation will dispatch the onUpdate events upon changing frame.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Animation.prototype, 'enableUpdate', {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return (this.onUpdate !== null);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value && this.onUpdate === null)
|
|
|
|
{
|
|
|
|
this.onUpdate = new Phaser.Signal();
|
|
|
|
}
|
|
|
|
else if (!value && this.onUpdate !== null)
|
|
|
|
{
|
|
|
|
this.onUpdate.dispose();
|
|
|
|
this.onUpdate = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
*
|
2013-10-02 00:16:40 +00:00
|
|
|
* @method Phaser.Animation.generateFrameNames
|
2014-09-15 23:28:09 +00:00
|
|
|
* @static
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} prefix - The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'.
|
2013-10-24 03:27:28 +00:00
|
|
|
* @param {number} start - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1.
|
|
|
|
* @param {number} stop - The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value is 34.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} [suffix=''] - The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'.
|
2015-09-23 13:04:04 +00:00
|
|
|
* @param {number} [zeroPad=0] - The number of zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
|
2014-11-30 11:10:52 +00:00
|
|
|
* @return {string[]} An array of framenames.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-10-24 03:27:28 +00:00
|
|
|
Phaser.Animation.generateFrameNames = function (prefix, start, stop, suffix, zeroPad) {
|
2013-09-27 08:57:08 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (suffix === undefined) { suffix = ''; }
|
2013-09-27 08:57:08 +00:00
|
|
|
|
|
|
|
var output = [];
|
|
|
|
var frame = '';
|
|
|
|
|
2013-10-24 03:27:28 +00:00
|
|
|
if (start < stop)
|
2013-09-27 08:57:08 +00:00
|
|
|
{
|
2013-10-24 03:27:28 +00:00
|
|
|
for (var i = start; i <= stop; i++)
|
2013-09-27 08:57:08 +00:00
|
|
|
{
|
2014-10-11 03:52:06 +00:00
|
|
|
if (typeof zeroPad === 'number')
|
2013-10-24 03:27:28 +00:00
|
|
|
{
|
|
|
|
// str, len, pad, dir
|
|
|
|
frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame = i.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = prefix + frame + suffix;
|
|
|
|
|
|
|
|
output.push(frame);
|
2013-09-27 08:57:08 +00:00
|
|
|
}
|
2013-10-24 03:27:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (var i = start; i >= stop; i--)
|
2013-09-27 08:57:08 +00:00
|
|
|
{
|
2014-10-11 03:52:06 +00:00
|
|
|
if (typeof zeroPad === 'number')
|
2013-10-24 03:27:28 +00:00
|
|
|
{
|
|
|
|
// str, len, pad, dir
|
|
|
|
frame = Phaser.Utils.pad(i.toString(), zeroPad, '0', 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame = i.toString();
|
|
|
|
}
|
2013-09-27 08:57:08 +00:00
|
|
|
|
2013-10-24 03:27:28 +00:00
|
|
|
frame = prefix + frame + suffix;
|
2013-09-27 08:57:08 +00:00
|
|
|
|
2013-10-24 03:27:28 +00:00
|
|
|
output.push(frame);
|
|
|
|
}
|
2013-09-27 08:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
2014-03-23 08:10:01 +00:00
|
|
|
};
|