2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-04 16:14:43 +00:00
|
|
|
var Clamp = require('../math/Clamp');
|
2018-01-16 13:04:35 +00:00
|
|
|
var Class = require('../utils/Class');
|
2019-01-15 14:37:24 +00:00
|
|
|
var Events = require('./events');
|
2018-04-04 16:14:43 +00:00
|
|
|
var FindClosestInSorted = require('../utils/array/FindClosestInSorted');
|
2018-01-16 12:59:05 +00:00
|
|
|
var Frame = require('./AnimationFrame');
|
2018-01-16 13:04:35 +00:00
|
|
|
var GetValue = require('../utils/object/GetValue');
|
2020-09-03 16:44:46 +00:00
|
|
|
var SortByDigits = require('../utils/array/SortByDigits');
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A Frame based Animation.
|
2018-03-19 12:54:20 +00:00
|
|
|
*
|
2020-09-08 11:17:18 +00:00
|
|
|
* Animations in Phaser consist of a sequence of `AnimationFrame` objects, which are managed by
|
|
|
|
* this class, along with properties that impact playback, such as the animations frame rate
|
|
|
|
* or delay.
|
2018-03-19 12:54:20 +00:00
|
|
|
*
|
2020-09-08 11:17:18 +00:00
|
|
|
* This class contains all of the properties and methods needed to handle playback of the animation
|
|
|
|
* directly to an `AnimationState` instance, which is owned by a Sprite, or similar Game Object.
|
|
|
|
*
|
|
|
|
* You don't typically create an instance of this class directly, but instead go via
|
|
|
|
* either the `AnimationManager` or the `AnimationState` and use their `create` methods,
|
|
|
|
* depending on if you need a global animation, or local to a specific Sprite.
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
|
|
|
* @class Animation
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Animations
|
2018-02-07 15:27:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-01-28 17:12:28 +00:00
|
|
|
* @param {Phaser.Animations.AnimationManager} manager - A reference to the global Animation Manager
|
|
|
|
* @param {string} key - The unique identifying string for this animation.
|
2019-05-09 10:46:07 +00:00
|
|
|
* @param {Phaser.Types.Animations.Animation} config - The Animation configuration.
|
2018-02-07 15:27:21 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
var Animation = new Class({
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
initialize:
|
2017-04-04 15:50:28 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
function Animation (manager, key, config)
|
|
|
|
{
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* A reference to the global Animation Manager.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#manager
|
|
|
|
* @type {Phaser.Animations.AnimationManager}
|
2018-01-21 13:19:58 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.manager = manager;
|
2017-04-12 12:53:55 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* The unique identifying string for this animation.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#key
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.key = key;
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* A frame based animation (as opposed to a bone based animation)
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-22 01:07:30 +00:00
|
|
|
* @name Phaser.Animations.Animation#type
|
2018-02-07 15:27:21 +00:00
|
|
|
* @type {string}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default frame
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.type = 'frame';
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* Extract all the frame data into the frames array.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#frames
|
2018-03-19 16:55:21 +00:00
|
|
|
* @type {Phaser.Animations.AnimationFrame[]}
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2018-01-16 12:59:05 +00:00
|
|
|
this.frames = this.getFrames(
|
|
|
|
manager.textureManager,
|
|
|
|
GetValue(config, 'frames', []),
|
2020-09-03 16:44:46 +00:00
|
|
|
GetValue(config, 'defaultTextureKey', null),
|
|
|
|
GetValue(config, 'sortFrames', true)
|
2018-01-16 12:59:05 +00:00
|
|
|
);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* The frame rate of playback in frames per second (default 24 if duration is null)
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#frameRate
|
|
|
|
* @type {integer}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 24
|
2018-01-21 13:19:58 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-07-27 07:22:52 +00:00
|
|
|
this.frameRate = GetValue(config, 'frameRate', null);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* How long the animation should play for, in milliseconds.
|
|
|
|
* If the `frameRate` property has been set then it overrides this value,
|
|
|
|
* otherwise the `frameRate` is derived from `duration`.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#duration
|
|
|
|
* @type {integer}
|
2018-01-21 13:19:58 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.duration = GetValue(config, 'duration', null);
|
2017-04-05 00:15:53 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* How many ms per frame, not including frame specific modifiers.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#msPerFrame
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2020-09-02 16:43:44 +00:00
|
|
|
this.msPerFrame;
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* Skip frames if the time lags, or always advanced anyway?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#skipMissedFrames
|
|
|
|
* @type {boolean}
|
2020-09-07 15:03:06 +00:00
|
|
|
* @default true
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* The delay in ms before the playback will begin.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#delay
|
|
|
|
* @type {integer}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 0
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.delay = GetValue(config, 'delay', 0);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Number of times to repeat the animation. Set to -1 to repeat forever.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#repeat
|
|
|
|
* @type {integer}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 0
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.repeat = GetValue(config, 'repeat', 0);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* The delay in ms before the a repeat play starts.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#repeatDelay
|
|
|
|
* @type {integer}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 0
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
|
2017-04-10 13:38:44 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* Should the animation yoyo (reverse back down to the start) before repeating?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#yoyo
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.yoyo = GetValue(config, 'yoyo', false);
|
2017-04-10 13:38:44 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* Should the GameObject's `visible` property be set to `true` when the animation starts to play?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#showOnStart
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.showOnStart = GetValue(config, 'showOnStart', false);
|
2017-04-10 15:27:32 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2019-01-28 17:12:28 +00:00
|
|
|
* Should the GameObject's `visible` property be set to `false` when the animation finishes?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#hideOnComplete
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
|
2017-04-10 15:27:32 +00:00
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Global pause. All Game Objects using this Animation instance are impacted by this property.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.Animation#paused
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-02-07 15:27:21 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-06-30 14:47:51 +00:00
|
|
|
this.paused = false;
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2020-09-02 16:43:44 +00:00
|
|
|
this.calculateDuration(this, this.getTotalFrames(), this.duration, this.frameRate);
|
|
|
|
|
2020-09-04 12:06:00 +00:00
|
|
|
if (this.manager.on)
|
|
|
|
{
|
|
|
|
this.manager.on(Events.PAUSE_ALL, this.pause, this);
|
|
|
|
this.manager.on(Events.RESUME_ALL, this.resume, this);
|
|
|
|
}
|
2017-06-30 14:47:51 +00:00
|
|
|
},
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2020-09-02 16:43:44 +00:00
|
|
|
/**
|
|
|
|
* Gets the total number of frames in this animation.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getTotalFrames
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @return {number} The total number of frames in this animation.
|
|
|
|
*/
|
|
|
|
getTotalFrames: function ()
|
|
|
|
{
|
|
|
|
return this.frames.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the duration, frame rate and msPerFrame values.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#calculateDuration
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {(Phaser.Animations.Animation|Phaser.GameObjects.Components.Animation)} target - The target to set the values on.
|
|
|
|
* @param {number} totalFrames - The total number of frames in the animation.
|
|
|
|
* @param {number} duration - The duration to calculate the frame rate from.
|
|
|
|
* @param {number} frameRate - The frame ate to calculate the duration from.
|
|
|
|
*/
|
|
|
|
calculateDuration: function (target, totalFrames, duration, frameRate)
|
|
|
|
{
|
|
|
|
if (duration === null && frameRate === null)
|
|
|
|
{
|
|
|
|
// No duration or frameRate given, use default frameRate of 24fps
|
|
|
|
target.frameRate = 24;
|
|
|
|
target.duration = (24 / totalFrames) * 1000;
|
|
|
|
}
|
|
|
|
else if (duration && frameRate === null)
|
|
|
|
{
|
|
|
|
// Duration given but no frameRate, so set the frameRate based on duration
|
|
|
|
// I.e. 12 frames in the animation, duration = 4000 ms
|
|
|
|
// So frameRate is 12 / (4000 / 1000) = 3 fps
|
|
|
|
target.duration = duration;
|
|
|
|
target.frameRate = totalFrames / (duration / 1000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// frameRate given, derive duration from it (even if duration also specified)
|
|
|
|
// I.e. 15 frames in the animation, frameRate = 30 fps
|
|
|
|
// So duration is 15 / 30 = 0.5 * 1000 (half a second, or 500ms)
|
|
|
|
target.frameRate = frameRate;
|
|
|
|
target.duration = (totalFrames / frameRate) * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.msPerFrame = 1000 / target.frameRate;
|
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Add frames to the end of the animation.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#addFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {(string|Phaser.Types.Animations.AnimationFrame[])} config - Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
addFrame: function (config)
|
|
|
|
{
|
|
|
|
return this.addFrameAt(this.frames.length, config);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Add frame/s into the animation.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#addFrameAt
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-01-28 17:12:28 +00:00
|
|
|
* @param {integer} index - The index to insert the frame at within the animation.
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {(string|Phaser.Types.Animations.AnimationFrame[])} config - Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
addFrameAt: function (index, config)
|
|
|
|
{
|
|
|
|
var newFrames = this.getFrames(this.manager.textureManager, config);
|
|
|
|
|
|
|
|
if (newFrames.length > 0)
|
|
|
|
{
|
|
|
|
if (index === 0)
|
|
|
|
{
|
|
|
|
this.frames = newFrames.concat(this.frames);
|
|
|
|
}
|
|
|
|
else if (index === this.frames.length)
|
|
|
|
{
|
|
|
|
this.frames = this.frames.concat(newFrames);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var pre = this.frames.slice(0, index);
|
|
|
|
var post = this.frames.slice(index);
|
|
|
|
|
|
|
|
this.frames = pre.concat(newFrames, post);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateFrameSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Check if the given frame index is valid.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#checkFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {integer} index - The index to be checked.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @return {boolean} `true` if the index is valid, otherwise `false`.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
checkFrame: function (index)
|
|
|
|
{
|
2018-04-04 15:13:45 +00:00
|
|
|
return (index >= 0 && index < this.frames.length);
|
2018-01-16 12:59:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Called internally when this Animation first starts to play.
|
|
|
|
* Sets the accumulator and nextTick properties.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getFirstTick
|
2018-04-04 15:13:45 +00:00
|
|
|
* @protected
|
2018-01-16 12:59:05 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component belonging to the Game Object invoking this call.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
2020-09-03 16:44:46 +00:00
|
|
|
getFirstTick: function (component)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
|
|
|
// When is the first update due?
|
|
|
|
component.accumulator = 0;
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
component.nextTick = component.msPerFrame + component.currentFrame.duration;
|
2018-01-16 12:59:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-19 15:36:13 +00:00
|
|
|
* Returns the AnimationFrame at the provided index
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getFrameAt
|
2018-04-04 15:13:45 +00:00
|
|
|
* @protected
|
2018-01-16 12:59:05 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-19 15:36:13 +00:00
|
|
|
* @param {integer} index - The index in the AnimationFrame array
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2018-04-19 15:36:13 +00:00
|
|
|
* @return {Phaser.Animations.AnimationFrame} The frame at the index provided from the animation sequence
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
getFrameAt: function (index)
|
|
|
|
{
|
|
|
|
return this.frames[index];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Creates AnimationFrame instances based on the given frame data.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getFrames
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.Textures.TextureManager} textureManager - A reference to the global Texture Manager.
|
|
|
|
* @param {(string|Phaser.Types.Animations.AnimationFrame[])} frames - Either a string, in which case it will use all frames from a texture with the matching key, or an array of Animation Frame configuration objects.
|
|
|
|
* @param {string} [defaultTextureKey] - The key to use if no key is set in the frame configuration object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @return {Phaser.Animations.AnimationFrame[]} An array of newly created AnimationFrame instances.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
2020-09-03 16:44:46 +00:00
|
|
|
getFrames: function (textureManager, frames, defaultTextureKey, sortFrames)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
if (sortFrames === undefined) { sortFrames = true; }
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
var out = [];
|
|
|
|
var prev;
|
|
|
|
var animationFrame;
|
|
|
|
var index = 1;
|
|
|
|
var i;
|
|
|
|
var textureKey;
|
|
|
|
|
|
|
|
// if frames is a string, we'll get all the frames from the texture manager as if it's a sprite sheet
|
|
|
|
if (typeof frames === 'string')
|
|
|
|
{
|
|
|
|
textureKey = frames;
|
|
|
|
|
|
|
|
var texture = textureManager.get(textureKey);
|
|
|
|
var frameKeys = texture.getFrameNames();
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (sortFrames)
|
|
|
|
{
|
|
|
|
SortByDigits(frameKeys);
|
|
|
|
}
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
frames = [];
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
frameKeys.forEach(function (value)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
|
|
|
frames.push({ key: textureKey, frame: value });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.isArray(frames) || frames.length === 0)
|
|
|
|
{
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < frames.length; i++)
|
|
|
|
{
|
|
|
|
var item = frames[i];
|
|
|
|
|
|
|
|
var key = GetValue(item, 'key', defaultTextureKey);
|
|
|
|
|
|
|
|
if (!key)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-01-24 23:50:46 +00:00
|
|
|
// Could be an integer or a string
|
2018-01-16 12:59:05 +00:00
|
|
|
var frame = GetValue(item, 'frame', 0);
|
|
|
|
|
2018-01-24 23:50:46 +00:00
|
|
|
// The actual texture frame
|
2018-01-16 12:59:05 +00:00
|
|
|
var textureFrame = textureManager.getFrame(key, frame);
|
|
|
|
|
|
|
|
animationFrame = new Frame(key, frame, index, textureFrame);
|
|
|
|
|
|
|
|
animationFrame.duration = GetValue(item, 'duration', 0);
|
|
|
|
|
|
|
|
animationFrame.isFirst = (!prev);
|
|
|
|
|
|
|
|
// The previously created animationFrame
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
prev.nextFrame = animationFrame;
|
|
|
|
|
|
|
|
animationFrame.prevFrame = prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.push(animationFrame);
|
|
|
|
|
|
|
|
prev = animationFrame;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out.length > 0)
|
|
|
|
{
|
|
|
|
animationFrame.isLast = true;
|
|
|
|
|
|
|
|
// Link them end-to-end, so they loop
|
|
|
|
animationFrame.nextFrame = out[0];
|
|
|
|
|
|
|
|
out[0].prevFrame = animationFrame;
|
|
|
|
|
|
|
|
// Generate the progress data
|
|
|
|
|
|
|
|
var slice = 1 / (out.length - 1);
|
|
|
|
|
|
|
|
for (i = 0; i < out.length; i++)
|
|
|
|
{
|
|
|
|
out[i].progress = i * slice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Called internally. Sets the accumulator and nextTick values of the current Animation.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getNextTick
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component belonging to the Game Object invoking this call.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
getNextTick: function (component)
|
|
|
|
{
|
|
|
|
component.accumulator -= component.nextTick;
|
|
|
|
|
|
|
|
component.nextTick = component.msPerFrame + component.currentFrame.duration;
|
|
|
|
},
|
|
|
|
|
2018-04-04 16:14:43 +00:00
|
|
|
/**
|
|
|
|
* Returns the frame closest to the given progress value between 0 and 1.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getFrameByProgress
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} value - A value between 0 and 1.
|
2018-04-04 16:14:43 +00:00
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @return {Phaser.Animations.AnimationFrame} The frame closest to the given progress value.
|
2018-04-04 16:14:43 +00:00
|
|
|
*/
|
|
|
|
getFrameByProgress: function (value)
|
|
|
|
{
|
|
|
|
value = Clamp(value, 0, 1);
|
|
|
|
|
|
|
|
return FindClosestInSorted(value, this.frames, 'progress');
|
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2018-06-01 12:11:25 +00:00
|
|
|
* Advance the animation frame.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#nextFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to advance.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
nextFrame: function (component)
|
|
|
|
{
|
|
|
|
var frame = component.currentFrame;
|
|
|
|
|
|
|
|
if (frame.isLast)
|
|
|
|
{
|
|
|
|
// We're at the end of the animation
|
|
|
|
|
|
|
|
// Yoyo? (happens before repeat)
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.yoyo)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
2018-09-07 16:19:19 +00:00
|
|
|
this.handleYoyoFrame(component, false);
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
else if (component.repeatCounter > 0)
|
|
|
|
{
|
|
|
|
// Repeat (happens before complete)
|
2018-07-22 17:57:07 +00:00
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.inReverse && component.forward)
|
2018-07-22 17:57:07 +00:00
|
|
|
{
|
|
|
|
component.forward = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.repeatAnimation(component);
|
|
|
|
}
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
component.complete();
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-07 16:19:19 +00:00
|
|
|
this.updateAndGetNextTick(component, frame.nextFrame);
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-09-01 15:40:26 +00:00
|
|
|
/**
|
|
|
|
* Handle the yoyo functionality in nextFrame and previousFrame methods.
|
|
|
|
*
|
2018-09-07 16:19:19 +00:00
|
|
|
* @method Phaser.Animations.Animation#handleYoyoFrame
|
|
|
|
* @private
|
2018-09-01 15:40:26 +00:00
|
|
|
* @since 3.12.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component to advance.
|
2018-09-07 16:19:19 +00:00
|
|
|
* @param {boolean} isReverse - Is animation in reverse mode? (Default: false)
|
2018-09-01 15:40:26 +00:00
|
|
|
*/
|
2018-09-07 16:19:19 +00:00
|
|
|
handleYoyoFrame: function (component, isReverse)
|
2018-09-01 15:40:26 +00:00
|
|
|
{
|
|
|
|
if (!isReverse) { isReverse = false; }
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.inReverse === !isReverse && component.repeatCounter > 0)
|
2018-09-01 15:40:26 +00:00
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.repeatDelay === 0 || component.pendingRepeat)
|
2020-04-27 13:40:42 +00:00
|
|
|
{
|
|
|
|
component.forward = isReverse;
|
|
|
|
}
|
2018-09-07 16:19:19 +00:00
|
|
|
|
2018-09-01 15:40:26 +00:00
|
|
|
this.repeatAnimation(component);
|
2018-09-07 16:19:19 +00:00
|
|
|
|
2018-09-01 15:40:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.inReverse !== isReverse && component.repeatCounter === 0)
|
2018-09-01 15:40:26 +00:00
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
component.complete();
|
2018-09-07 16:19:19 +00:00
|
|
|
|
2018-09-01 15:40:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-09-02 13:42:26 +00:00
|
|
|
|
2018-09-01 15:40:26 +00:00
|
|
|
component.forward = isReverse;
|
2018-09-07 16:19:19 +00:00
|
|
|
|
|
|
|
var frame = (isReverse) ? component.currentFrame.nextFrame : component.currentFrame.prevFrame;
|
|
|
|
|
|
|
|
this.updateAndGetNextTick(component, frame);
|
2018-09-01 15:40:26 +00:00
|
|
|
},
|
|
|
|
|
2018-07-22 14:44:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the animation last frame.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#getLastFrame
|
2018-07-24 12:28:56 +00:00
|
|
|
* @since 3.12.0
|
2018-07-22 14:44:57 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Animations.AnimationFrame} component - The Animation Last Frame.
|
|
|
|
*/
|
|
|
|
getLastFrame: function ()
|
|
|
|
{
|
|
|
|
return this.frames[this.frames.length - 1];
|
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Called internally when the Animation is playing backwards.
|
|
|
|
* Sets the previous frame, causing a yoyo, repeat, complete or update, accordingly.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#previousFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component belonging to the Game Object invoking this call.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
previousFrame: function (component)
|
|
|
|
{
|
|
|
|
var frame = component.currentFrame;
|
|
|
|
|
|
|
|
if (frame.isFirst)
|
|
|
|
{
|
|
|
|
// We're at the start of the animation
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.yoyo)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
2018-09-07 16:19:19 +00:00
|
|
|
this.handleYoyoFrame(component, true);
|
2018-07-22 17:57:07 +00:00
|
|
|
}
|
|
|
|
else if (component.repeatCounter > 0)
|
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.inReverse && !component.forward)
|
2018-07-22 14:44:57 +00:00
|
|
|
{
|
2018-09-01 15:40:26 +00:00
|
|
|
this.repeatAnimation(component);
|
2018-07-22 14:44:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Repeat (happens before complete)
|
2018-07-22 17:57:07 +00:00
|
|
|
component.forward = true;
|
2020-09-03 16:44:46 +00:00
|
|
|
|
2018-07-22 14:44:57 +00:00
|
|
|
this.repeatAnimation(component);
|
|
|
|
}
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-03 16:44:46 +00:00
|
|
|
component.complete();
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-07 16:19:19 +00:00
|
|
|
this.updateAndGetNextTick(component, frame.prevFrame);
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-22 17:57:07 +00:00
|
|
|
/**
|
2018-09-07 16:19:19 +00:00
|
|
|
* Update Frame and Wait next tick.
|
2018-07-22 17:57:07 +00:00
|
|
|
*
|
2018-09-07 16:19:19 +00:00
|
|
|
* @method Phaser.Animations.Animation#updateAndGetNextTick
|
|
|
|
* @private
|
2018-07-24 12:28:56 +00:00
|
|
|
* @since 3.12.0
|
2018-07-22 17:57:07 +00:00
|
|
|
*
|
2018-09-07 16:19:19 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - An Animation frame.
|
2018-07-22 17:57:07 +00:00
|
|
|
*/
|
2018-09-07 16:19:19 +00:00
|
|
|
updateAndGetNextTick: function (component, frame)
|
2018-07-22 17:57:07 +00:00
|
|
|
{
|
2020-09-05 10:12:52 +00:00
|
|
|
component.setCurrentFrame(frame);
|
2018-09-07 16:19:19 +00:00
|
|
|
|
2018-07-22 17:57:07 +00:00
|
|
|
this.getNextTick(component);
|
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Removes the given AnimationFrame from this Animation instance.
|
|
|
|
* This is a global action. Any Game Object using this Animation will be impacted by this change.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#removeFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - The AnimationFrame to be removed.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
removeFrame: function (frame)
|
|
|
|
{
|
|
|
|
var index = this.frames.indexOf(frame);
|
|
|
|
|
|
|
|
if (index !== -1)
|
|
|
|
{
|
|
|
|
this.removeFrameAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-19 15:36:13 +00:00
|
|
|
* Removes a frame from the AnimationFrame array at the provided index
|
|
|
|
* and updates the animation accordingly.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#removeFrameAt
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-19 15:36:13 +00:00
|
|
|
* @param {integer} index - The index in the AnimationFrame array
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
removeFrameAt: function (index)
|
|
|
|
{
|
|
|
|
this.frames.splice(index, 1);
|
|
|
|
|
|
|
|
this.updateFrameSequence();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Called internally during playback. Forces the animation to repeat, providing there are enough counts left
|
|
|
|
* in the repeat counter.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#repeatAnimation
|
2019-01-15 14:37:24 +00:00
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_REPEAT
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_REPEAT
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_REPEAT
|
2018-01-16 12:59:05 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.Animation} component - The Animation Component belonging to the Game Object invoking this call.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
repeatAnimation: function (component)
|
|
|
|
{
|
2018-04-07 11:36:11 +00:00
|
|
|
if (component._pendingStop === 2)
|
|
|
|
{
|
2020-09-04 10:40:32 +00:00
|
|
|
if (component._pendingStopValue === 0)
|
|
|
|
{
|
|
|
|
return component.stop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
component._pendingStopValue--;
|
|
|
|
}
|
2018-04-07 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.repeatDelay > 0 && !component.pendingRepeat)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
|
|
|
component.pendingRepeat = true;
|
|
|
|
component.accumulator -= component.nextTick;
|
2020-09-03 16:44:46 +00:00
|
|
|
component.nextTick += component.repeatDelay;
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
component.repeatCounter--;
|
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
if (component.forward)
|
|
|
|
{
|
2020-09-05 10:12:52 +00:00
|
|
|
component.setCurrentFrame(component.currentFrame.nextFrame);
|
2020-09-03 16:44:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-05 10:12:52 +00:00
|
|
|
component.setCurrentFrame(component.currentFrame.prevFrame);
|
2020-09-03 16:44:46 +00:00
|
|
|
}
|
2018-01-16 12:59:05 +00:00
|
|
|
|
2018-04-07 11:36:11 +00:00
|
|
|
if (component.isPlaying)
|
|
|
|
{
|
|
|
|
this.getNextTick(component);
|
2018-01-16 12:59:05 +00:00
|
|
|
|
2020-09-03 16:44:46 +00:00
|
|
|
component.handleRepeat();
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-10-19 11:32:43 +00:00
|
|
|
* Converts the animation data to JSON.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#toJSON
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 16:53:33 +00:00
|
|
|
* @return {Phaser.Types.Animations.JSONAnimation} The resulting JSONAnimation formatted object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
toJSON: function ()
|
|
|
|
{
|
|
|
|
var output = {
|
|
|
|
key: this.key,
|
|
|
|
type: this.type,
|
|
|
|
frames: [],
|
|
|
|
frameRate: this.frameRate,
|
|
|
|
duration: this.duration,
|
|
|
|
skipMissedFrames: this.skipMissedFrames,
|
|
|
|
delay: this.delay,
|
|
|
|
repeat: this.repeat,
|
|
|
|
repeatDelay: this.repeatDelay,
|
|
|
|
yoyo: this.yoyo,
|
|
|
|
showOnStart: this.showOnStart,
|
|
|
|
hideOnComplete: this.hideOnComplete
|
|
|
|
};
|
|
|
|
|
|
|
|
this.frames.forEach(function (frame)
|
|
|
|
{
|
|
|
|
output.frames.push(frame.toJSON());
|
|
|
|
});
|
|
|
|
|
|
|
|
return output;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Called internally whenever frames are added to, or removed from, this Animation.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#updateFrameSequence
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
|
|
|
updateFrameSequence: function ()
|
|
|
|
{
|
|
|
|
var len = this.frames.length;
|
|
|
|
var slice = 1 / (len - 1);
|
|
|
|
|
2019-07-03 14:07:53 +00:00
|
|
|
var frame;
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{
|
2019-07-03 14:07:53 +00:00
|
|
|
frame = this.frames[i];
|
2018-01-16 12:59:05 +00:00
|
|
|
|
|
|
|
frame.index = i + 1;
|
|
|
|
frame.isFirst = false;
|
|
|
|
frame.isLast = false;
|
|
|
|
frame.progress = i * slice;
|
|
|
|
|
|
|
|
if (i === 0)
|
|
|
|
{
|
|
|
|
frame.isFirst = true;
|
2019-07-03 14:07:53 +00:00
|
|
|
|
|
|
|
if (len === 1)
|
|
|
|
{
|
|
|
|
frame.isLast = true;
|
|
|
|
frame.nextFrame = frame;
|
|
|
|
frame.prevFrame = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame.isLast = false;
|
|
|
|
frame.prevFrame = this.frames[len - 1];
|
|
|
|
frame.nextFrame = this.frames[i + 1];
|
|
|
|
}
|
2018-01-16 12:59:05 +00:00
|
|
|
}
|
2019-07-03 14:07:53 +00:00
|
|
|
else if (i === len - 1 && len > 1)
|
2018-01-16 12:59:05 +00:00
|
|
|
{
|
|
|
|
frame.isLast = true;
|
|
|
|
frame.prevFrame = this.frames[len - 2];
|
|
|
|
frame.nextFrame = this.frames[0];
|
|
|
|
}
|
|
|
|
else if (len > 1)
|
|
|
|
{
|
|
|
|
frame.prevFrame = this.frames[i - 1];
|
|
|
|
frame.nextFrame = this.frames[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Pauses playback of this Animation. The paused state is set immediately.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
2017-05-02 15:49:48 +00:00
|
|
|
pause: function ()
|
|
|
|
{
|
|
|
|
this.paused = true;
|
2018-01-16 12:59:05 +00:00
|
|
|
|
|
|
|
return this;
|
2017-05-02 15:49:48 +00:00
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Resumes playback of this Animation. The paused state is reset immediately.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#resume
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-01-30 15:13:27 +00:00
|
|
|
* @return {this} This Animation object.
|
2018-01-16 12:59:05 +00:00
|
|
|
*/
|
2017-05-02 15:49:48 +00:00
|
|
|
resume: function ()
|
|
|
|
{
|
|
|
|
this.paused = false;
|
2018-01-16 12:59:05 +00:00
|
|
|
|
|
|
|
return this;
|
2017-05-02 15:49:48 +00:00
|
|
|
},
|
|
|
|
|
2018-01-16 12:59:05 +00:00
|
|
|
/**
|
2020-02-04 16:53:33 +00:00
|
|
|
* Destroys this Animation instance. It will remove all event listeners,
|
|
|
|
* remove this animation and its key from the global Animation Manager,
|
|
|
|
* and then destroy all Animation Frames in turn.
|
2018-01-16 12:59:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Animations.Animation#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-04 15:32:33 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2020-09-04 12:06:00 +00:00
|
|
|
if (this.manager.off)
|
|
|
|
{
|
|
|
|
this.manager.off(Events.PAUSE_ALL, this.pause, this);
|
|
|
|
this.manager.off(Events.RESUME_ALL, this.resume, this);
|
|
|
|
}
|
2018-04-04 16:14:43 +00:00
|
|
|
|
|
|
|
this.manager.remove(this.key);
|
|
|
|
|
|
|
|
for (var i = 0; i < this.frames.length; i++)
|
|
|
|
{
|
|
|
|
this.frames[i].destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.frames = [];
|
|
|
|
|
|
|
|
this.manager = null;
|
2017-04-04 15:32:33 +00:00
|
|
|
}
|
2017-06-30 14:47:51 +00:00
|
|
|
|
|
|
|
});
|
2017-04-04 15:32:33 +00:00
|
|
|
|
|
|
|
module.exports = Animation;
|