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
|
|
|
*/
|
|
|
|
|
2020-09-08 08:31:59 +00:00
|
|
|
var AnimationState = require('../../animations/AnimationState');
|
2017-02-23 03:54:54 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Components = require('../components');
|
2017-12-15 04:07:45 +00:00
|
|
|
var GameObject = require('../GameObject');
|
2020-08-24 18:24:02 +00:00
|
|
|
var GameObjectEvents = require('../events');
|
2017-02-23 03:54:54 +00:00
|
|
|
var SpriteRender = require('./SpriteRender');
|
|
|
|
|
2018-02-06 14:13:30 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2018-02-06 14:13:30 +00:00
|
|
|
* A Sprite Game Object.
|
|
|
|
*
|
|
|
|
* A Sprite Game Object is used for the display of both static and animated images in your game.
|
2018-02-09 03:44:23 +00:00
|
|
|
* Sprites can have input events and physics bodies. They can also be tweened, tinted, scrolled
|
2018-02-06 14:13:30 +00:00
|
|
|
* and animated.
|
|
|
|
*
|
|
|
|
* The main difference between a Sprite and an Image Game Object is that you cannot animate Images.
|
|
|
|
* As such, Sprites take a fraction longer to process and have a larger API footprint due to the Animation
|
|
|
|
* Component. If you do not require animation then you can safely use Images to replace Sprites in all cases.
|
|
|
|
*
|
|
|
|
* @class Sprite
|
|
|
|
* @extends Phaser.GameObjects.GameObject
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.GameObjects
|
2018-02-06 14:13:30 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @extends Phaser.GameObjects.Components.Alpha
|
|
|
|
* @extends Phaser.GameObjects.Components.BlendMode
|
|
|
|
* @extends Phaser.GameObjects.Components.Depth
|
|
|
|
* @extends Phaser.GameObjects.Components.Flip
|
|
|
|
* @extends Phaser.GameObjects.Components.GetBounds
|
2018-04-20 17:57:49 +00:00
|
|
|
* @extends Phaser.GameObjects.Components.Mask
|
2018-02-06 14:13:30 +00:00
|
|
|
* @extends Phaser.GameObjects.Components.Origin
|
|
|
|
* @extends Phaser.GameObjects.Components.Pipeline
|
|
|
|
* @extends Phaser.GameObjects.Components.ScrollFactor
|
|
|
|
* @extends Phaser.GameObjects.Components.Size
|
2018-07-05 12:06:28 +00:00
|
|
|
* @extends Phaser.GameObjects.Components.TextureCrop
|
2018-02-06 14:13:30 +00:00
|
|
|
* @extends Phaser.GameObjects.Components.Tint
|
|
|
|
* @extends Phaser.GameObjects.Components.Transform
|
|
|
|
* @extends Phaser.GameObjects.Components.Visible
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world.
|
2020-07-13 12:29:01 +00:00
|
|
|
* @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-20 14:56:31 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
2018-02-06 14:13:30 +00:00
|
|
|
*/
|
2017-02-23 03:54:54 +00:00
|
|
|
var Sprite = new Class({
|
|
|
|
|
2017-04-05 01:10:48 +00:00
|
|
|
Extends: GameObject,
|
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
2018-02-01 00:50:15 +00:00
|
|
|
Components.Depth,
|
2017-04-04 22:59:16 +00:00
|
|
|
Components.Flip,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.GetBounds,
|
2018-04-20 17:57:49 +00:00
|
|
|
Components.Mask,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.Origin,
|
2018-01-29 21:46:48 +00:00
|
|
|
Components.Pipeline,
|
2017-07-04 11:01:27 +00:00
|
|
|
Components.ScrollFactor,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.Size,
|
2018-07-05 12:06:28 +00:00
|
|
|
Components.TextureCrop,
|
2017-07-04 11:01:27 +00:00
|
|
|
Components.Tint,
|
2017-03-02 02:06:13 +00:00
|
|
|
Components.Transform,
|
2017-02-23 03:54:54 +00:00
|
|
|
Components.Visible,
|
|
|
|
SpriteRender
|
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
function Sprite (scene, x, y, texture, frame)
|
2017-02-23 03:54:54 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
GameObject.call(this, scene, 'Sprite');
|
2017-02-23 03:54:54 +00:00
|
|
|
|
2018-07-18 23:18:09 +00:00
|
|
|
/**
|
|
|
|
* The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Sprite#_crop
|
|
|
|
* @type {object}
|
|
|
|
* @private
|
|
|
|
* @since 3.11.0
|
|
|
|
*/
|
2018-08-03 17:50:36 +00:00
|
|
|
this._crop = this.resetCropObject();
|
2018-07-18 23:18:09 +00:00
|
|
|
|
2018-02-06 14:13:30 +00:00
|
|
|
/**
|
2020-09-05 10:45:00 +00:00
|
|
|
* The Animation State component of this Sprite.
|
|
|
|
*
|
|
|
|
* This component provides features to apply animations to this Sprite.
|
|
|
|
* It is responsible for playing, loading, queuing animations for later playback,
|
|
|
|
* mixing between animations and setting the current animation frame to this Sprite.
|
2018-02-06 14:13:30 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Sprite#anims
|
2020-09-08 08:31:59 +00:00
|
|
|
* @type {Phaser.Animations.AnimationState}
|
2018-02-06 14:13:30 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-09-08 08:31:59 +00:00
|
|
|
this.anims = new AnimationState(this);
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-02-23 03:54:54 +00:00
|
|
|
this.setTexture(texture, frame);
|
2017-03-02 02:06:13 +00:00
|
|
|
this.setPosition(x, y);
|
2017-03-02 04:00:39 +00:00
|
|
|
this.setSizeToFrame();
|
2018-02-09 15:23:26 +00:00
|
|
|
this.setOriginFromFrame();
|
2018-09-05 10:19:02 +00:00
|
|
|
this.initPipeline();
|
2020-08-24 18:24:02 +00:00
|
|
|
|
|
|
|
this.on(GameObjectEvents.ADDED_TO_SCENE, this.addedToScene, this);
|
|
|
|
this.on(GameObjectEvents.REMOVED_FROM_SCENE, this.removedFromScene, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Overrides Game Object method
|
|
|
|
addedToScene: function ()
|
|
|
|
{
|
|
|
|
this.scene.sys.updateList.add(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Overrides Game Object method
|
|
|
|
removedFromScene: function ()
|
|
|
|
{
|
|
|
|
this.scene.sys.updateList.remove(this);
|
2017-04-04 22:59:16 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 14:13:30 +00:00
|
|
|
/**
|
2018-06-08 14:50:44 +00:00
|
|
|
* Update this Sprite's animations.
|
2018-02-06 14:13:30 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#preUpdate
|
2018-04-18 12:29:22 +00:00
|
|
|
* @protected
|
2018-02-06 14:13:30 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-08 14:50:44 +00:00
|
|
|
* @param {number} time - The current timestamp.
|
|
|
|
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
|
2018-02-06 14:13:30 +00:00
|
|
|
*/
|
2017-07-04 22:43:13 +00:00
|
|
|
preUpdate: function (time, delta)
|
2017-04-04 22:59:16 +00:00
|
|
|
{
|
2017-07-04 22:43:13 +00:00
|
|
|
this.anims.update(time, delta);
|
2017-04-05 03:41:53 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 14:13:30 +00:00
|
|
|
/**
|
2020-09-03 16:38:36 +00:00
|
|
|
* Start playing the given animation on this Sprite.
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite.
|
|
|
|
*
|
|
|
|
* The benefit of a global animation is that multiple Sprites can all play the same animation, without
|
|
|
|
* having to duplicate the data. You can just create it once and then play it on any Sprite.
|
|
|
|
*
|
|
|
|
* The following code shows how to create a global repeating animation. The animation will be created
|
2020-09-03 16:38:36 +00:00
|
|
|
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* var config = {
|
|
|
|
* key: 'run',
|
|
|
|
* frames: 'muybridge',
|
|
|
|
* frameRate: 15,
|
|
|
|
* repeat: -1
|
|
|
|
* };
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* // This code should be run from within a Scene:
|
2020-09-03 16:38:36 +00:00
|
|
|
* this.anims.create(config);
|
|
|
|
* ```
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone,
|
|
|
|
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
|
|
|
|
* creating a global animation, however the resulting data is kept locally in this Sprite.
|
|
|
|
*
|
|
|
|
* With the animation created, either globally or locally, you can now play it on this Sprite:
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* this.add.sprite(x, y).play('run');
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config
|
|
|
|
* object instead:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* this.add.sprite(x, y).play({ key: 'run', frameRate: 24 });
|
|
|
|
* ```
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* When playing an animation on a Sprite it will first check to see if it can find a matching key
|
|
|
|
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
|
|
|
|
* search the global Animation Manager and look for it there.
|
|
|
|
*
|
|
|
|
* If you need a Sprite to be able to play both local and global animations, make sure they don't
|
|
|
|
* have conflicting keys.
|
|
|
|
*
|
2020-09-03 16:38:36 +00:00
|
|
|
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
|
|
|
|
*
|
|
|
|
* Also, see the documentation in the Animation Manager for further details on creating animations.
|
2018-02-06 14:13:30 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#play
|
2020-09-02 16:41:43 +00:00
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
|
2018-02-06 14:13:30 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-09-02 16:41:43 +00:00
|
|
|
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
2018-06-08 14:50:44 +00:00
|
|
|
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
2018-02-06 14:13:30 +00:00
|
|
|
*
|
2020-01-26 13:36:59 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-06 14:13:30 +00:00
|
|
|
*/
|
2020-09-04 10:48:17 +00:00
|
|
|
play: function (key, ignoreIfPlaying)
|
2017-04-05 03:41:53 +00:00
|
|
|
{
|
2020-09-04 10:48:17 +00:00
|
|
|
return this.anims.play(key, ignoreIfPlaying);
|
2017-04-12 23:35:27 +00:00
|
|
|
},
|
|
|
|
|
2020-09-03 16:38:36 +00:00
|
|
|
/**
|
2020-09-04 12:58:34 +00:00
|
|
|
* Start playing the given animation on this Sprite, in reverse.
|
|
|
|
*
|
|
|
|
* Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite.
|
|
|
|
*
|
|
|
|
* The benefit of a global animation is that multiple Sprites can all play the same animation, without
|
|
|
|
* having to duplicate the data. You can just create it once and then play it on any Sprite.
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* The following code shows how to create a global repeating animation. The animation will be created
|
2020-09-03 16:38:36 +00:00
|
|
|
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* var config = {
|
|
|
|
* key: 'run',
|
|
|
|
* frames: 'muybridge',
|
|
|
|
* frameRate: 15,
|
|
|
|
* repeat: -1
|
|
|
|
* };
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* // This code should be run from within a Scene:
|
2020-09-03 16:38:36 +00:00
|
|
|
* this.anims.create(config);
|
|
|
|
* ```
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone,
|
|
|
|
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
|
|
|
|
* creating a global animation, however the resulting data is kept locally in this Sprite.
|
|
|
|
*
|
|
|
|
* With the animation created, either globally or locally, you can now play it on this Sprite:
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* this.add.sprite(x, y).playReverse('run');
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config
|
|
|
|
* object instead:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* this.add.sprite(x, y).playReverse({ key: 'run', frameRate: 24 });
|
|
|
|
* ```
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* When playing an animation on a Sprite it will first check to see if it can find a matching key
|
|
|
|
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
|
|
|
|
* search the global Animation Manager and look for it there.
|
|
|
|
*
|
|
|
|
* If you need a Sprite to be able to play both local and global animations, make sure they don't
|
|
|
|
* have conflicting keys.
|
|
|
|
*
|
2020-09-03 16:38:36 +00:00
|
|
|
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
|
|
|
|
*
|
|
|
|
* Also, see the documentation in the Animation Manager for further details on creating animations.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#playReverse
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
|
|
|
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
2020-09-04 10:48:17 +00:00
|
|
|
playReverse: function (key, ignoreIfPlaying)
|
2020-09-03 16:38:36 +00:00
|
|
|
{
|
2020-09-04 10:48:17 +00:00
|
|
|
return this.anims.playReverse(key, ignoreIfPlaying);
|
2020-09-03 16:38:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-09-04 10:48:17 +00:00
|
|
|
* Waits for the specified delay, in milliseconds, then starts playback of the given animation.
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* If the animation _also_ has a delay value set in its config, it will be **added** to the delay given here.
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* If an animation is already running and a new animation is given to this method, it will wait for
|
|
|
|
* the given delay before starting the new animation.
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* If no animation is currently running, the given one begins after the delay.
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* When playing an animation on a Sprite it will first check to see if it can find a matching key
|
|
|
|
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
|
|
|
|
* search the global Animation Manager and look for it there.
|
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* Prior to Phaser 3.50 this method was called 'delayedPlay'.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Animation#playAfterDelay
|
2020-09-03 16:38:36 +00:00
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
2020-09-03 16:38:36 +00:00
|
|
|
* @param {integer} delay - The delay, in milliseconds, to wait before starting the animation playing.
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
playAfterDelay: function (key, delay)
|
|
|
|
{
|
|
|
|
return this.anims.playAfterDelay(key, delay);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-09-04 12:58:34 +00:00
|
|
|
* Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback
|
|
|
|
* of the given animation.
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* You can use this to ensure there are no harsh jumps between two sets of animations, i.e. going from an
|
|
|
|
* idle animation to a walking animation, by making them blend smoothly into each other.
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
|
|
|
* If no animation is currently running, the given one will start immediately.
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* When playing an animation on a Sprite it will first check to see if it can find a matching key
|
|
|
|
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
|
|
|
|
* search the global Animation Manager and look for it there.
|
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Animation#playAfterRepeat
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
2020-09-03 16:38:36 +00:00
|
|
|
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
2020-09-04 10:48:17 +00:00
|
|
|
* @param {integer} [repeatCount=1] - How many times should the animation repeat before the next one starts?
|
2020-09-03 16:38:36 +00:00
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
2020-09-04 10:48:17 +00:00
|
|
|
playAfterRepeat: function (key, repeatCount)
|
2020-09-03 16:38:36 +00:00
|
|
|
{
|
2020-09-04 10:48:17 +00:00
|
|
|
return this.anims.playAfterRepeat(key, repeatCount);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an animation, or an array of animations, to be played immediately after the current one completes or stops.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* An animation set to repeat forever will never enter a completed state.
|
|
|
|
*
|
2020-09-04 12:58:34 +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` event).
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* Chained animations are specific to a Game Object, meaning different Game Objects can have different chained
|
|
|
|
* animations without impacting the animation they're playing.
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
|
|
|
* Call this method with no arguments to reset all currently chained animations.
|
|
|
|
*
|
2020-09-04 12:58:34 +00:00
|
|
|
* When playing an animation on a Sprite it will first check to see if it can find a matching key
|
|
|
|
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
|
|
|
|
* search the global Animation Manager and look for it there.
|
|
|
|
*
|
2020-09-04 10:48:17 +00:00
|
|
|
* @method Phaser.GameObjects.Sprite#chain
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig|string[]|Phaser.Animations.Animation[]|Phaser.Types.Animations.PlayAnimationConfig[])} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object, or an array of them.
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
chain: function (key)
|
|
|
|
{
|
|
|
|
return this.anims.chain(key);
|
2020-09-03 16:38:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` events.
|
|
|
|
*
|
|
|
|
* If no animation is playing, no event will be dispatched.
|
|
|
|
*
|
|
|
|
* If there is another animation queued (via the `chain` method) then it will start playing immediately.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#stop
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
stop: function ()
|
|
|
|
{
|
|
|
|
return this.anims.stop();
|
|
|
|
},
|
|
|
|
|
2020-09-04 10:48:17 +00:00
|
|
|
/**
|
|
|
|
* Stops the current animation from playing after the specified time delay, given in milliseconds.
|
|
|
|
*
|
|
|
|
* It then dispatches the `ANIMATION_STOP` series of events.
|
|
|
|
*
|
|
|
|
* If no animation is running, no events will be dispatched.
|
|
|
|
*
|
|
|
|
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
|
|
|
* when the current one stops.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#stopAfterDelay
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {integer} delay - The number of milliseconds to wait before stopping this animation.
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
stopAfterDelay: function (delay)
|
|
|
|
{
|
|
|
|
return this.anims.stopAfterDelay(delay);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-09-04 12:58:34 +00:00
|
|
|
* Stops the current animation from playing after the given number of repeats.
|
2020-09-04 10:48:17 +00:00
|
|
|
*
|
|
|
|
* It then dispatches the `ANIMATION_STOP` series of events.
|
|
|
|
*
|
|
|
|
* If no animation is running, no events will be dispatched.
|
|
|
|
*
|
|
|
|
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
|
|
|
* when the current one stops.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#stopAfterRepeat
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {integer} [repeatCount=1] - How many times should the animation repeat before stopping?
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
stopAfterRepeat: function (repeatCount)
|
|
|
|
{
|
|
|
|
return this.anims.stopAfterRepeat(repeatCount);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* It then dispatches the `ANIMATION_STOP` series of events.
|
|
|
|
*
|
|
|
|
* If no animation is running, no events will be dispatched.
|
|
|
|
*
|
|
|
|
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
|
|
|
* when the current one stops.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#stopOnFrame
|
|
|
|
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
|
|
|
|
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
|
|
|
|
* @since 3.50.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Animations.AnimationFrame} frame - The frame to check before stopping this animation.
|
|
|
|
*
|
|
|
|
* @return {this} This Game Object.
|
|
|
|
*/
|
|
|
|
stopOnFrame: function (frame)
|
|
|
|
{
|
|
|
|
return this.anims.stopOnFrame(frame);
|
|
|
|
},
|
|
|
|
|
2018-02-06 14:13:30 +00:00
|
|
|
/**
|
2018-06-08 14:50:44 +00:00
|
|
|
* Build a JSON representation of this Sprite.
|
2018-02-06 14:13:30 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#toJSON
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-05-09 11:01:00 +00:00
|
|
|
* @return {Phaser.Types.GameObjects.JSONGameObject} A JSON representation of the Game Object.
|
2018-02-06 14:13:30 +00:00
|
|
|
*/
|
2017-04-12 23:35:27 +00:00
|
|
|
toJSON: function ()
|
|
|
|
{
|
2020-09-03 16:38:36 +00:00
|
|
|
return Components.ToJSON(this);
|
2018-09-25 14:11:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the pre-destroy step for the Sprite, which removes the Animation component.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Sprite#preDestroy
|
|
|
|
* @private
|
|
|
|
* @since 3.14.0
|
|
|
|
*/
|
|
|
|
preDestroy: function ()
|
|
|
|
{
|
|
|
|
this.anims.destroy();
|
|
|
|
|
|
|
|
this.anims = undefined;
|
2017-01-24 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Sprite;
|