2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
var BaseAnimation = require('../../animations/Animation');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2018-04-07 14:58:08 +00:00
|
|
|
/**
|
|
|
|
* This event is dispatched when an animation starts playing.
|
2018-09-27 14:55:16 +00:00
|
|
|
*
|
|
|
|
* Listen for it on the Game Object: `sprite.on('animationstart', listener)`
|
2018-12-06 15:28:32 +00:00
|
|
|
*
|
|
|
|
* You can also listen for a specific animation by appending a hyphen and its key to the event name. For example,
|
|
|
|
* if you have an animation called `explode`, you can listen for `sprite.on('animationstart-explode', listener)`.
|
2018-12-06 15:39:57 +00:00
|
|
|
*
|
|
|
|
* You can also listen for the `start` event from the Animation itself: `animation.on('start', listener)`.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-07 14:58:08 +00:00
|
|
|
* @event Phaser.GameObjects.Components.Animation#onStartEvent
|
|
|
|
* @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation.
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame.
|
2018-09-27 14:55:16 +00:00
|
|
|
* @param {Phaser.GameObjects.Sprite} gameObject - Reference to the Game Object on which the event occurred.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is dispatched when an animation restarts.
|
|
|
|
*
|
|
|
|
* Listen for it on the Game Object: `sprite.on('animationrestart', listener)`
|
2018-12-06 15:28:32 +00:00
|
|
|
*
|
|
|
|
* You can also listen for a specific animation by appending a hyphen and its key to the event name. For example,
|
|
|
|
* if you have an animation called `explode`, you can listen for `sprite.on('animationrestart-explode', listener)`.
|
2018-12-06 15:39:57 +00:00
|
|
|
*
|
|
|
|
* You can also listen for the `restart` event from the Animation itself: `animation.on('restart', listener)`.
|
2018-09-27 14:55:16 +00:00
|
|
|
*
|
|
|
|
* @event Phaser.GameObjects.Components.Animation#onRestartEvent
|
|
|
|
* @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation.
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame.
|
|
|
|
* @param {Phaser.GameObjects.Sprite} gameObject - Reference to the Game Object on which the event occurred.
|
2018-04-07 14:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is dispatched when an animation repeats.
|
2018-09-27 14:55:16 +00:00
|
|
|
*
|
|
|
|
* Listen for it on the Game Object: `sprite.on('animationrepeat', listener)`
|
2018-12-06 15:28:32 +00:00
|
|
|
*
|
|
|
|
* You can also listen for a specific animation by appending a hyphen and its key to the event name. For example,
|
|
|
|
* if you have an animation called `explode`, you can listen for `sprite.on('animationrepeat-explode', listener)`.
|
2018-12-06 15:39:57 +00:00
|
|
|
*
|
|
|
|
* You can also listen for the `repeat` event from the Animation itself: `animation.on('repeat', listener)`.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-07 14:58:08 +00:00
|
|
|
* @event Phaser.GameObjects.Components.Animation#onRepeatEvent
|
|
|
|
* @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation.
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame.
|
|
|
|
* @param {integer} repeatCount - The number of times this animation has repeated.
|
2018-09-27 14:55:16 +00:00
|
|
|
* @param {Phaser.GameObjects.Sprite} gameObject - Reference to the Game Object on which the event occurred.
|
2018-04-07 14:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is dispatched when an animation updates. This happens when the animation frame changes,
|
|
|
|
* based on the animation frame rate and other factors like timeScale and delay.
|
2018-09-27 14:55:16 +00:00
|
|
|
*
|
|
|
|
* Listen for it on the Game Object: `sprite.on('animationupdate', listener)`
|
2018-12-06 15:28:32 +00:00
|
|
|
*
|
|
|
|
* You can also listen for a specific animation by appending a hyphen and its key to the event name. For example,
|
|
|
|
* if you have an animation called `explode`, you can listen for `sprite.on('animationupdate-explode', listener)`.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-07 14:58:08 +00:00
|
|
|
* @event Phaser.GameObjects.Components.Animation#onUpdateEvent
|
|
|
|
* @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation.
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame.
|
2018-09-27 14:55:16 +00:00
|
|
|
* @param {Phaser.GameObjects.Sprite} gameObject - Reference to the Game Object on which the event occurred.
|
2018-04-07 14:58:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event is dispatched when an animation completes playing, either naturally or via Animation.stop.
|
2018-09-27 14:55:16 +00:00
|
|
|
*
|
|
|
|
* Listen for it on the Game Object: `sprite.on('animationcomplete', listener)`
|
2018-12-06 15:28:32 +00:00
|
|
|
*
|
|
|
|
* You can also listen for a specific animation by appending a hyphen and its key to the event name. For example,
|
|
|
|
* if you have an animation called `explode`, you can listen for `sprite.on('animationcomplete-explode', listener)`.
|
2018-12-06 15:39:57 +00:00
|
|
|
*
|
|
|
|
* You can also listen for the `complete` event from the Animation itself: `animation.on('complete', listener)`.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-07 14:58:08 +00:00
|
|
|
* @event Phaser.GameObjects.Components.Animation#onCompleteEvent
|
|
|
|
* @param {Phaser.Animations.Animation} animation - Reference to the currently playing animation.
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - Reference to the current Animation Frame.
|
2018-09-27 14:55:16 +00:00
|
|
|
* @param {Phaser.GameObjects.Sprite} gameObject - Reference to the Game Object on which the event occurred.
|
2018-04-07 14:58:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2018-02-06 16:37:35 +00:00
|
|
|
* A Game Object Animation Controller.
|
|
|
|
*
|
|
|
|
* This controller lives as an instance within a Game Object, accessible as `sprite.anims`.
|
|
|
|
*
|
|
|
|
* @class Animation
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.GameObjects.Components
|
2018-02-06 16:37:35 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} parent - The Game Object to which this animation controller belongs.
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
var Animation = new Class({
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
initialize:
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
function Animation (parent)
|
2017-04-05 01:06:28 +00:00
|
|
|
{
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* The Game Object to which this animation controller belongs.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#parent
|
|
|
|
* @type {Phaser.GameObjects.GameObject}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.parent = parent;
|
2017-04-05 01:06:28 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* A reference to the global Animation Manager.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#animationManager
|
|
|
|
* @type {Phaser.Animations.AnimationManager}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
this.animationManager = parent.scene.sys.anims;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
this.animationManager.once('remove', this.remove, this);
|
2017-05-02 15:02:49 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Is an animation currently playing or not?
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#isPlaying
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.isPlaying = false;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* The current Animation loaded into this Animation Controller.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#currentAnim
|
|
|
|
* @type {?Phaser.Animations.Animation}
|
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.currentAnim = null;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* The current AnimationFrame being displayed by this Animation Controller.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#currentFrame
|
|
|
|
* @type {?Phaser.Animations.AnimationFrame}
|
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.currentFrame = null;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2018-12-06 15:57:52 +00:00
|
|
|
/**
|
|
|
|
* The key of the next Animation to be loaded into this Animation Controller when the current animation completes.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#nextAnim
|
|
|
|
* @type {?string}
|
|
|
|
* @default null
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.nextAnim = null;
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Time scale factor.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_timeScale
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:34:06 +00:00
|
|
|
this._timeScale = 1;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* The frame rate of playback in frames per second.
|
|
|
|
* The default is 24 if the `duration` property is `null`.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#frameRate
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.frameRate = 0;
|
2017-04-05 00:15:53 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* How long the animation should play for, in milliseconds.
|
2018-02-06 16:37:35 +00:00
|
|
|
* If the `frameRate` property has been set then it overrides this value,
|
2018-04-04 15:13:45 +00:00
|
|
|
* otherwise the `frameRate` is derived from `duration`.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#duration
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.duration = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* ms per frame, not including frame specific modifiers that may be present in the Animation data.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#msPerFrame
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.msPerFrame = 0;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Skip frames if the time lags, or always advanced anyway?
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#skipMissedFrames
|
|
|
|
* @type {boolean}
|
|
|
|
* @default true
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.skipMissedFrames = true;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* A delay before starting playback, in milliseconds.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_delay
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:29:20 +00:00
|
|
|
this._delay = 0;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Number of times to repeat the animation (-1 for infinity)
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_repeat
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:29:20 +00:00
|
|
|
this._repeat = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Delay before the repeat starts, in milliseconds.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_repeatDelay
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:29:20 +00:00
|
|
|
this._repeatDelay = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Should the animation yoyo? (reverse back down to the start) before repeating?
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_yoyo
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:29:20 +00:00
|
|
|
this._yoyo = false;
|
2017-04-05 00:15:53 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-07-22 17:57:07 +00:00
|
|
|
* Will the playhead move forwards (`true`) or in reverse (`false`).
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#forward
|
|
|
|
* @type {boolean}
|
|
|
|
* @default true
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-05 01:06:28 +00:00
|
|
|
this.forward = true;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2018-07-22 17:57:07 +00:00
|
|
|
/**
|
|
|
|
* An Internal trigger that's play the animation in reverse mode ('true') or not ('false'),
|
|
|
|
* needed because forward can be changed by yoyo feature.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#forward
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
2018-07-24 12:28:56 +00:00
|
|
|
* @since 3.12.0
|
2018-07-22 17:57:07 +00:00
|
|
|
*/
|
|
|
|
this._reverse = false;
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Internal time overflow accumulator.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#accumulator
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.accumulator = 0;
|
2018-02-06 16:37:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The time point at which the next animation frame will change.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#nextTick
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.nextTick = 0;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* An internal counter keeping track of how many repeats are left to play.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#repeatCounter
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this.repeatCounter = 0;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* An internal flag keeping track of pending repeats.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#pendingRepeat
|
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-05 23:58:48 +00:00
|
|
|
this.pendingRepeat = false;
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
|
|
|
* Is the Animation paused?
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_paused
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this._paused = false;
|
2018-02-06 16:37:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Was the animation previously playing before being paused?
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#_wasPlaying
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-04-06 23:07:20 +00:00
|
|
|
this._wasPlaying = false;
|
2017-04-10 15:27:32 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-07 11:36:35 +00:00
|
|
|
* Internal property tracking if this Animation is waiting to stop.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-07 11:36:35 +00:00
|
|
|
* 0 = No
|
|
|
|
* 1 = Waiting for ms to pass
|
|
|
|
* 2 = Waiting for repeat
|
|
|
|
* 3 = Waiting for specific frame
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-07 11:36:35 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Animation#_pendingStop
|
|
|
|
* @type {integer}
|
2018-02-06 16:37:35 +00:00
|
|
|
* @private
|
2018-04-07 11:36:35 +00:00
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-07 11:36:35 +00:00
|
|
|
this._pendingStop = 0;
|
2018-02-06 16:37:35 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-07 11:36:35 +00:00
|
|
|
* Internal property used by _pendingStop.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-07 11:36:35 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Animation#_pendingStopValue
|
|
|
|
* @type {any}
|
2018-02-06 16:37:35 +00:00
|
|
|
* @private
|
2018-04-07 11:36:35 +00:00
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-07 11:36:35 +00:00
|
|
|
this._pendingStopValue;
|
2017-04-05 23:58:48 +00:00
|
|
|
},
|
|
|
|
|
2018-12-06 15:57:52 +00:00
|
|
|
/**
|
|
|
|
* Sets an animation to be played immediately after the current one completes.
|
|
|
|
*
|
2018-12-06 15:59:22 +00:00
|
|
|
* The current animation must enter a 'completed' state for this to happen, i.e. finish all of its repeats, delays, etc, or have the `stop` method called directly on it.
|
2018-12-06 15:57:52 +00:00
|
|
|
*
|
|
|
|
* An animation set to repeat forever will never enter a completed state.
|
|
|
|
*
|
2018-12-06 15:59:22 +00:00
|
|
|
* You can chain a new animation at any point, including before the current one starts playing, during it, or when it ends (via its `animationcomplete` callback).
|
|
|
|
* Chained animations are specific to a Game Object, meaning different Game Objects can have different chained animations without impacting the global animation they're playing.
|
|
|
|
*
|
2018-12-06 15:57:52 +00:00
|
|
|
* Call this method with no arguments to reset the chained animation.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#chain
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @param {(string|Phaser.Animations.Animation)} [key] - The string-based key of the animation to play next, as defined previously in the Animation Manager. Or an Animation instance.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
chain: function (key)
|
|
|
|
{
|
|
|
|
if (key instanceof BaseAnimation)
|
|
|
|
{
|
|
|
|
key = key.key;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nextAnim = key;
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Sets the amount of time, in milliseconds, that the animation will be delayed before starting playback.
|
2018-03-19 11:54:31 +00:00
|
|
|
*
|
2018-04-16 14:11:51 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#setDelay
|
2018-04-04 13:44:09 +00:00
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {integer} [value=0] - The amount of time, in milliseconds, to wait before starting playback.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
setDelay: function (value)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
if (value === undefined) { value = 0; }
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
this._delay = value;
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Gets the amount of time, in milliseconds that the animation will be delayed before starting playback.
|
2018-04-04 13:44:09 +00:00
|
|
|
*
|
2018-04-16 14:11:51 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getDelay
|
2018-04-04 13:44:09 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @return {integer} The amount of time, in milliseconds, the Animation will wait before starting playback.
|
2018-04-04 13:44:09 +00:00
|
|
|
*/
|
|
|
|
getDelay: function ()
|
|
|
|
{
|
|
|
|
return this._delay;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Waits for the specified delay, in milliseconds, then starts playback of the requested animation.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#delayedPlay
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {integer} delay - The delay, in milliseconds, to wait before starting the animation playing.
|
|
|
|
* @param {string} key - The key of the animation to play.
|
|
|
|
* @param {integer} [startFrame=0] - The frame of the animation to start from.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
delayedPlay: function (delay, key, startFrame)
|
|
|
|
{
|
|
|
|
this.play(key, true, startFrame);
|
|
|
|
|
2018-04-04 15:27:33 +00:00
|
|
|
this.nextTick += delay;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Returns the key of the animation currently loaded into this component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#getCurrentKey
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @return {string} The key of the Animation loaded into this component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
getCurrentKey: function ()
|
|
|
|
{
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
return this.currentAnim.key;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Internal method used to load an animation into this component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#load
|
2018-04-04 15:13:45 +00:00
|
|
|
* @protected
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {string} key - The key of the animation to load.
|
|
|
|
* @param {integer} [startFrame=0] - The start frame of the animation to load.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
load: function (key, startFrame)
|
|
|
|
{
|
|
|
|
if (startFrame === undefined) { startFrame = 0; }
|
|
|
|
|
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the new animation in
|
|
|
|
this.animationManager.load(this, key, startFrame);
|
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Pause the current animation and set the `isPlaying` property to `false`.
|
|
|
|
* You can optionally pause it at a specific frame.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} [atFrame] - An optional frame to set after pausing the animation.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
pause: function (atFrame)
|
|
|
|
{
|
|
|
|
if (!this._paused)
|
|
|
|
{
|
|
|
|
this._paused = true;
|
|
|
|
this._wasPlaying = this.isPlaying;
|
|
|
|
this.isPlaying = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atFrame !== undefined)
|
|
|
|
{
|
|
|
|
this.updateFrame(atFrame);
|
|
|
|
}
|
2018-03-19 11:54:31 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 15:13:45 +00:00
|
|
|
* Resumes playback of a paused animation and sets the `isPlaying` property to `true`.
|
|
|
|
* You can optionally tell it to start playback from a specific frame.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#resume
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} [fromFrame] - An optional frame to set before restarting playback.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
resume: function (fromFrame)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
if (this._paused)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
this._paused = false;
|
|
|
|
this.isPlaying = this._wasPlaying;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
2018-04-04 13:44:09 +00:00
|
|
|
|
|
|
|
if (fromFrame !== undefined)
|
|
|
|
{
|
|
|
|
this.updateFrame(fromFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* `true` if the current animation is paused, otherwise `false`.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Animation#isPaused
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-04-04 13:44:09 +00:00
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
isPaused: {
|
|
|
|
|
|
|
|
get: function ()
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
|
|
|
return this._paused;
|
|
|
|
}
|
2018-04-04 13:44:09 +00:00
|
|
|
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-12-06 15:28:32 +00:00
|
|
|
* Plays an Animation on a Game Object that has the Animation component, such as a Sprite.
|
|
|
|
*
|
|
|
|
* Animations are stored in the global Animation Manager and are referenced by a unique string-based key.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#play
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onStartEvent
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-12-06 15:28:32 +00:00
|
|
|
* @param {(string|Phaser.Animations.Animation)} key - The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance.
|
2018-04-04 15:13:45 +00:00
|
|
|
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
|
|
|
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
play: function (key, ignoreIfPlaying, startFrame)
|
|
|
|
{
|
|
|
|
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
|
|
|
|
if (startFrame === undefined) { startFrame = 0; }
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
if (key instanceof BaseAnimation)
|
|
|
|
{
|
|
|
|
key = key.key;
|
|
|
|
}
|
|
|
|
|
2018-01-16 15:39:18 +00:00
|
|
|
if (ignoreIfPlaying && this.isPlaying && this.currentAnim.key === key)
|
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 15:42:59 +00:00
|
|
|
this.forward = true;
|
2018-07-22 17:57:07 +00:00
|
|
|
this._reverse = false;
|
2018-08-31 17:45:50 +00:00
|
|
|
|
2018-07-22 15:42:59 +00:00
|
|
|
return this._startAnimation(key, startFrame);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plays an Animation (in reverse mode) on the Game Object that owns this Animation Component.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#playReverse
|
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onStartEvent
|
2018-07-24 12:28:56 +00:00
|
|
|
* @since 3.12.0
|
2018-07-22 15:42:59 +00:00
|
|
|
*
|
2018-12-06 15:28:32 +00:00
|
|
|
* @param {(string|Phaser.Animations.Animation)} key - The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance.
|
2018-07-22 15:42:59 +00:00
|
|
|
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
|
|
|
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
playReverse: function (key, ignoreIfPlaying, startFrame)
|
|
|
|
{
|
|
|
|
if (ignoreIfPlaying === undefined) { ignoreIfPlaying = false; }
|
|
|
|
if (startFrame === undefined) { startFrame = 0; }
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
if (key instanceof BaseAnimation)
|
|
|
|
{
|
|
|
|
key = key.key;
|
|
|
|
}
|
|
|
|
|
2018-07-22 15:42:59 +00:00
|
|
|
if (ignoreIfPlaying && this.isPlaying && this.currentAnim.key === key)
|
|
|
|
{
|
|
|
|
return this.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.forward = false;
|
2018-07-22 17:57:07 +00:00
|
|
|
this._reverse = true;
|
2018-08-31 17:45:50 +00:00
|
|
|
|
2018-07-22 15:42:59 +00:00
|
|
|
return this._startAnimation(key, startFrame);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-12-06 15:28:32 +00:00
|
|
|
* Load an Animation and fires 'onStartEvent' event, extracted from 'play' method.
|
2018-07-22 15:42:59 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#_startAnimation
|
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onStartEvent
|
2018-07-24 12:28:56 +00:00
|
|
|
* @since 3.12.0
|
2018-07-22 15:42:59 +00:00
|
|
|
*
|
|
|
|
* @param {string} key - The string-based key of the animation to play, as defined previously in the Animation Manager.
|
|
|
|
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
_startAnimation: function (key, startFrame)
|
|
|
|
{
|
2018-01-16 15:39:18 +00:00
|
|
|
this.load(key, startFrame);
|
|
|
|
|
|
|
|
var anim = this.currentAnim;
|
2018-02-27 01:09:09 +00:00
|
|
|
var gameObject = this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
|
|
|
// Should give us 9,007,199,254,740,991 safe repeats
|
2018-01-18 14:59:32 +00:00
|
|
|
this.repeatCounter = (this._repeat === -1) ? Number.MAX_VALUE : this._repeat;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
|
|
|
anim.getFirstTick(this);
|
2018-07-24 12:28:56 +00:00
|
|
|
|
2018-01-16 15:39:18 +00:00
|
|
|
this.isPlaying = true;
|
|
|
|
this.pendingRepeat = false;
|
|
|
|
|
|
|
|
if (anim.showOnStart)
|
|
|
|
{
|
2018-02-27 01:09:09 +00:00
|
|
|
gameObject.visible = true;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
var frame = this.currentFrame;
|
|
|
|
|
|
|
|
anim.emit('start', anim, frame);
|
|
|
|
|
|
|
|
gameObject.emit('animationstart-' + key, anim, frame, gameObject);
|
|
|
|
|
|
|
|
gameObject.emit('animationstart', anim, frame, gameObject);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return gameObject;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-07-22 14:44:57 +00:00
|
|
|
/**
|
2018-12-06 15:28:32 +00:00
|
|
|
* Reverse the Animation that is already playing on the Game Object.
|
2018-07-22 14:44:57 +00:00
|
|
|
*
|
2018-07-24 12:28:56 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#reverse
|
|
|
|
* @since 3.12.0
|
2018-07-22 14:44:57 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
2018-12-06 15:28:32 +00:00
|
|
|
reverse: function ()
|
2018-07-22 14:44:57 +00:00
|
|
|
{
|
2018-12-06 15:28:32 +00:00
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
|
|
|
this._reverse = !this._reverse;
|
|
|
|
|
|
|
|
this.forward = !this.forward;
|
|
|
|
}
|
2018-07-22 14:44:57 +00:00
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Returns a value between 0 and 1 indicating how far this animation is through, ignoring repeats and yoyos.
|
|
|
|
* If the animation has a non-zero repeat defined, `getProgress` and `getTotalProgress` will be different
|
|
|
|
* because `getProgress` doesn't include any repeats or repeat delays, whereas `getTotalProgress` does.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getProgress
|
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-06-26 22:19:14 +00:00
|
|
|
* @return {number} The progress of the current animation, between 0 and 1.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
getProgress: function ()
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
var p = this.currentFrame.progress;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
if (!this.forward)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
p = 1 - p;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
2018-04-04 13:44:09 +00:00
|
|
|
|
|
|
|
return p;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-04-04 15:13:45 +00:00
|
|
|
/**
|
|
|
|
* Takes a value between 0 and 1 and uses it to set how far this animation is through playback.
|
2018-04-04 16:19:02 +00:00
|
|
|
* Does not factor in repeats or yoyos, but does handle playing forwards or backwards.
|
2018-04-04 15:13:45 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#setProgress
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-06-26 22:19:14 +00:00
|
|
|
* @param {number} [value=0] - The progress value, between 0 and 1.
|
2018-04-04 15:13:45 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
setProgress: function (value)
|
|
|
|
{
|
2018-04-04 16:19:02 +00:00
|
|
|
if (!this.forward)
|
|
|
|
{
|
|
|
|
value = 1 - value;
|
|
|
|
}
|
|
|
|
|
2018-04-30 11:37:50 +00:00
|
|
|
this.setCurrentFrame(this.currentAnim.getFrameByProgress(value));
|
2018-04-04 16:19:02 +00:00
|
|
|
|
2018-04-04 15:13:45 +00:00
|
|
|
return this.parent;
|
|
|
|
},
|
2018-04-04 13:44:09 +00:00
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-06-01 13:08:35 +00:00
|
|
|
* Handle the removal of an animation from the Animation Manager.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#remove
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 13:37:15 +00:00
|
|
|
* @param {string} [key] - The key of the removed Animation.
|
|
|
|
* @param {Phaser.Animations.Animation} [animation] - The removed Animation.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-06-01 13:37:15 +00:00
|
|
|
remove: function (key, animation)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-06-01 13:37:15 +00:00
|
|
|
if (animation === undefined) { animation = this.currentAnim; }
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-06-01 13:37:15 +00:00
|
|
|
if (this.isPlaying && animation.key === this.currentAnim.key)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
|
|
|
this.stop();
|
|
|
|
|
2018-04-04 12:14:41 +00:00
|
|
|
this.setCurrentFrame(this.currentAnim.frames[0]);
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Gets the number of times that the animation will repeat
|
|
|
|
* after its first iteration. For example, if returns 1, the animation will
|
|
|
|
* play a total of twice (the initial play plus 1 repeat).
|
|
|
|
* A value of -1 means the animation will repeat indefinitely.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#getRepeat
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return {integer} The number of times that the animation will repeat.
|
|
|
|
*/
|
|
|
|
getRepeat: function ()
|
|
|
|
{
|
|
|
|
return this._repeat;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the number of times that the animation should repeat
|
2018-03-19 11:54:31 +00:00
|
|
|
* after its first iteration. For example, if repeat is 1, the animation will
|
|
|
|
* play a total of twice (the initial play plus 1 repeat).
|
|
|
|
* To repeat indefinitely, use -1. repeat should always be an integer.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#setRepeat
|
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {integer} value - The number of times that the animation should repeat.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
setRepeat: function (value)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
this._repeat = value;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
this.repeatCounter = 0;
|
|
|
|
|
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Gets the amount of delay between repeats, if any.
|
2018-04-10 20:51:34 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getRepeatDelay
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return {number} The delay between repeats.
|
|
|
|
*/
|
|
|
|
getRepeatDelay: function ()
|
|
|
|
{
|
|
|
|
return this._repeatDelay;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the amount of time in seconds between repeats.
|
|
|
|
* For example, if `repeat` is 2 and `repeatDelay` is 10, the animation will play initially,
|
|
|
|
* then wait for 10 seconds before repeating, then play again, then wait another 10 seconds
|
2018-03-19 11:54:31 +00:00
|
|
|
* before doing its final repeat.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#setRepeatDelay
|
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @param {number} value - The delay to wait between repeats, in seconds.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
setRepeatDelay: function (value)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
this._repeatDelay = value;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Restarts the current animation from its beginning, optionally including its delay value.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#restart
|
2018-09-27 14:55:16 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onRestartEvent
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {boolean} [includeDelay=false] - Whether to include the delay value of the animation when restarting.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
restart: function (includeDelay)
|
|
|
|
{
|
|
|
|
if (includeDelay === undefined) { includeDelay = false; }
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
var anim = this.currentAnim;
|
|
|
|
|
|
|
|
anim.getFirstTick(this, includeDelay);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
|
|
|
this.forward = true;
|
|
|
|
this.isPlaying = true;
|
|
|
|
this.pendingRepeat = false;
|
|
|
|
this._paused = false;
|
|
|
|
|
|
|
|
// Set frame
|
2018-12-06 15:28:32 +00:00
|
|
|
this.updateFrame(anim.frames[0]);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-09-27 14:55:16 +00:00
|
|
|
var gameObject = this.parent;
|
2018-12-06 15:28:32 +00:00
|
|
|
var frame = this.currentFrame;
|
2018-09-27 14:55:16 +00:00
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
anim.emit('restart', anim, frame);
|
|
|
|
|
|
|
|
gameObject.emit('animationrestart-' + anim.key, anim, frame, gameObject);
|
|
|
|
|
|
|
|
gameObject.emit('animationrestart', anim, frame, gameObject);
|
2018-09-27 14:55:16 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-07 11:36:35 +00:00
|
|
|
* Immediately stops the current animation from playing and dispatches the `animationcomplete` event.
|
2018-12-06 15:57:52 +00:00
|
|
|
*
|
|
|
|
* If there is another animation queued (via the `chain` method) then it will start playing immediately.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#stop
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onCompleteEvent
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-07 11:36:35 +00:00
|
|
|
stop: function ()
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-07 11:36:35 +00:00
|
|
|
this._pendingStop = 0;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
|
|
|
this.isPlaying = false;
|
|
|
|
|
2018-04-07 11:36:35 +00:00
|
|
|
var gameObject = this.parent;
|
2018-12-06 15:28:32 +00:00
|
|
|
var anim = this.currentAnim;
|
|
|
|
var frame = this.currentFrame;
|
|
|
|
|
|
|
|
anim.on('complete', anim, frame);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
gameObject.emit('animationcomplete-' + anim.key, anim, frame, gameObject);
|
|
|
|
|
|
|
|
gameObject.emit('animationcomplete', anim, frame, gameObject);
|
2018-04-07 11:36:35 +00:00
|
|
|
|
2018-12-06 15:57:52 +00:00
|
|
|
if (this.nextAnim)
|
|
|
|
{
|
|
|
|
var key = this.nextAnim;
|
|
|
|
|
|
|
|
this.nextAnim = null;
|
|
|
|
|
|
|
|
this.play(key);
|
|
|
|
}
|
|
|
|
|
2018-04-07 11:36:35 +00:00
|
|
|
return gameObject;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the current animation from playing after the specified time delay, given in milliseconds.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#stopAfterDelay
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onCompleteEvent
|
2018-04-07 11:36:35 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-04-14 16:38:20 +00:00
|
|
|
* @param {integer} delay - The number of milliseconds to wait before stopping this animation.
|
2018-04-07 11:36:35 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
stopAfterDelay: function (delay)
|
|
|
|
{
|
|
|
|
this._pendingStop = 1;
|
|
|
|
this._pendingStopValue = delay;
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the current animation from playing when it next repeats.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#stopOnRepeat
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onCompleteEvent
|
2018-04-07 11:36:35 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
stopOnRepeat: function ()
|
|
|
|
{
|
|
|
|
this._pendingStop = 2;
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the current animation from playing when it next sets the given frame.
|
|
|
|
* If this frame doesn't exist within the animation it will not stop it from playing.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#stopOnFrame
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onCompleteEvent
|
2018-04-07 11:36:35 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-12-06 15:28:32 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - The frame to check before stopping this animation.
|
2018-04-07 11:36:35 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
|
|
|
*/
|
|
|
|
stopOnFrame: function (frame)
|
|
|
|
{
|
|
|
|
this._pendingStop = 3;
|
|
|
|
this._pendingStopValue = frame;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.parent;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Sets the Time Scale factor, allowing you to make the animation go go faster or slower than default.
|
|
|
|
* Where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#setTimeScale
|
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @param {number} [value=1] - The time scale factor, where 1 is no change, 0.5 is half speed, etc.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object that owns this Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
setTimeScale: function (value)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
if (value === undefined) { value = 1; }
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
this._timeScale = value;
|
|
|
|
|
|
|
|
return this.parent;
|
2017-05-02 15:02:49 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Gets the Time Scale factor.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getTimeScale
|
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {number} The Time Scale value.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
getTimeScale: function ()
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
return this._timeScale;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Returns the total number of frames in this animation.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getTotalFrames
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return {integer} The total number of frames in this animation.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 13:44:09 +00:00
|
|
|
getTotalFrames: function ()
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
return this.currentAnim.frames.length;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* The internal update loop for the Animation Component.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#update
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {number} time - The current timestamp.
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-06-01 12:11:25 +00:00
|
|
|
update: function (time, delta)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-13 07:58:33 +00:00
|
|
|
if (!this.currentAnim || !this.isPlaying || this.currentAnim.paused)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-13 07:58:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-13 07:58:33 +00:00
|
|
|
this.accumulator += delta * this._timeScale;
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-13 07:58:33 +00:00
|
|
|
if (this._pendingStop === 1)
|
|
|
|
{
|
|
|
|
this._pendingStopValue -= delta;
|
2018-04-10 20:51:34 +00:00
|
|
|
|
2018-04-13 07:58:33 +00:00
|
|
|
if (this._pendingStopValue <= 0)
|
2018-04-07 11:36:35 +00:00
|
|
|
{
|
2018-04-13 07:58:33 +00:00
|
|
|
return this.currentAnim.completeAnimation(this);
|
2018-04-07 11:36:35 +00:00
|
|
|
}
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
2018-04-13 07:58:33 +00:00
|
|
|
|
|
|
|
if (this.accumulator >= this.nextTick)
|
|
|
|
{
|
|
|
|
this.currentAnim.setFrame(this);
|
|
|
|
}
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-04-04 12:14:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the given Animation Frame as being the current frame
|
|
|
|
* and applies it to the parent Game Object, adjusting its size and origin as needed.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#setCurrentFrame
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} animationFrame - The Animation Frame to set as being current.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
|
|
|
|
*/
|
|
|
|
setCurrentFrame: function (animationFrame)
|
|
|
|
{
|
|
|
|
var gameObject = this.parent;
|
|
|
|
|
|
|
|
this.currentFrame = animationFrame;
|
|
|
|
|
|
|
|
gameObject.texture = animationFrame.frame.texture;
|
|
|
|
gameObject.frame = animationFrame.frame;
|
|
|
|
|
2018-09-27 15:49:52 +00:00
|
|
|
if (gameObject.isCropped)
|
|
|
|
{
|
|
|
|
gameObject.frame.updateCropUVs(gameObject._crop, gameObject.flipX, gameObject.flipY);
|
|
|
|
}
|
|
|
|
|
2018-04-04 12:14:41 +00:00
|
|
|
gameObject.setSizeToFrame();
|
|
|
|
|
|
|
|
if (animationFrame.frame.customPivot)
|
|
|
|
{
|
|
|
|
gameObject.setOrigin(animationFrame.frame.pivotX, animationFrame.frame.pivotY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gameObject.updateDisplayOrigin();
|
|
|
|
}
|
|
|
|
|
|
|
|
return gameObject;
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Internal frame change handler.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#updateFrame
|
2018-04-07 14:58:08 +00:00
|
|
|
* @fires Phaser.GameObjects.Components.Animation#onUpdateEvent
|
2018-04-04 13:44:09 +00:00
|
|
|
* @private
|
2018-02-06 16:37:35 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-01 12:11:25 +00:00
|
|
|
* @param {Phaser.Animations.AnimationFrame} animationFrame - The animation frame to change to.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
updateFrame: function (animationFrame)
|
|
|
|
{
|
2018-04-04 12:14:41 +00:00
|
|
|
var gameObject = this.setCurrentFrame(animationFrame);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
|
|
|
if (this.isPlaying)
|
|
|
|
{
|
|
|
|
if (animationFrame.setAlpha)
|
|
|
|
{
|
2018-04-04 12:14:41 +00:00
|
|
|
gameObject.alpha = animationFrame.alpha;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var anim = this.currentAnim;
|
|
|
|
|
2018-12-06 15:28:32 +00:00
|
|
|
gameObject.emit('animationupdate-' + anim.key, anim, animationFrame, gameObject);
|
|
|
|
|
2018-09-27 14:55:16 +00:00
|
|
|
gameObject.emit('animationupdate', anim, animationFrame, gameObject);
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-07 11:36:35 +00:00
|
|
|
if (this._pendingStop === 3 && this._pendingStopValue === animationFrame)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-07 11:36:35 +00:00
|
|
|
this.currentAnim.completeAnimation(this);
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-11-16 14:34:09 +00:00
|
|
|
/**
|
|
|
|
* Advances the animation to the next frame, regardless of the time or animation state.
|
|
|
|
* If the animation is set to repeat, or yoyo, this will still take effect.
|
|
|
|
*
|
|
|
|
* Calling this does not change the direction of the animation. I.e. if it was currently
|
|
|
|
* playing in reverse, calling this method doesn't then change the direction to forwards.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#nextFrame
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
|
|
|
|
*/
|
|
|
|
nextFrame: function ()
|
|
|
|
{
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
this.currentAnim.nextFrame(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances the animation to the previous frame, regardless of the time or animation state.
|
|
|
|
* If the animation is set to repeat, or yoyo, this will still take effect.
|
|
|
|
*
|
|
|
|
* Calling this does not change the direction of the animation. I.e. if it was currently
|
|
|
|
* playing in forwards, calling this method doesn't then change the direction to backwards.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#previousFrame
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
|
|
|
|
*/
|
|
|
|
previousFrame: function ()
|
|
|
|
{
|
|
|
|
if (this.currentAnim)
|
|
|
|
{
|
|
|
|
this.currentAnim.previousFrame(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-04-04 13:44:09 +00:00
|
|
|
* Sets if the current Animation will yoyo when it reaches the end.
|
|
|
|
* A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#setYoyo
|
2018-04-04 13:44:09 +00:00
|
|
|
* @since 3.4.0
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @param {boolean} [value=false] - `true` if the animation should yoyo, `false` to not.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
2018-04-04 13:44:09 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
|
2018-02-06 16:37:35 +00:00
|
|
|
*/
|
2018-04-04 15:13:45 +00:00
|
|
|
setYoyo: function (value)
|
2018-01-16 15:39:18 +00:00
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
if (value === undefined) { value = false; }
|
2018-01-16 15:39:18 +00:00
|
|
|
|
2018-04-04 13:44:09 +00:00
|
|
|
this._yoyo = value;
|
|
|
|
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets if the current Animation will yoyo when it reaches the end.
|
|
|
|
* A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again.
|
|
|
|
*
|
2018-04-04 15:13:45 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#getYoyo
|
2018-04-04 13:44:09 +00:00
|
|
|
* @since 3.4.0
|
|
|
|
*
|
|
|
|
* @return {boolean} `true` if the animation is set to yoyo, `false` if not.
|
|
|
|
*/
|
2018-04-04 15:13:45 +00:00
|
|
|
getYoyo: function ()
|
2018-04-04 13:44:09 +00:00
|
|
|
{
|
|
|
|
return this._yoyo;
|
2018-01-16 15:39:18 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 16:37:35 +00:00
|
|
|
/**
|
2018-06-01 12:11:25 +00:00
|
|
|
* Destroy this Animation component.
|
|
|
|
*
|
|
|
|
* Unregisters event listeners and cleans up its references.
|
2018-02-06 16:37:35 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-16 15:39:18 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-04-04 13:44:09 +00:00
|
|
|
this.animationManager.off('remove', this.remove, this);
|
|
|
|
|
|
|
|
this.animationManager = null;
|
|
|
|
this.parent = null;
|
|
|
|
|
|
|
|
this.currentAnim = null;
|
|
|
|
this.currentFrame = null;
|
2018-01-16 15:39:18 +00:00
|
|
|
}
|
2017-04-05 14:27:26 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-04 22:59:16 +00:00
|
|
|
module.exports = Animation;
|