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-01-16 13:04:35 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-10-13 10:56:52 +00:00
|
|
|
|
2018-03-19 16:55:21 +00:00
|
|
|
/**
|
|
|
|
* @typedef {object} JSONAnimationFrame
|
|
|
|
*
|
|
|
|
* @property {string} key - The key of the Texture this AnimationFrame uses.
|
2018-03-20 14:58:02 +00:00
|
|
|
* @property {(string|integer)} frame - The key of the Frame within the Texture that this AnimationFrame uses.
|
2018-03-19 16:55:21 +00:00
|
|
|
* @property {number} duration - Additional time (in ms) that this frame should appear for during playback.
|
|
|
|
*/
|
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A single frame in an Animation sequence.
|
|
|
|
*
|
|
|
|
* An AnimationFrame consists of a reference to the Texture it uses for rendering, references to other
|
|
|
|
* frames in the animation, and index data. It also has the ability to fire its own `onUpdate` callback
|
|
|
|
* and modify the animation timing.
|
|
|
|
*
|
|
|
|
* AnimationFrames are generated automatically by the Animation class.
|
|
|
|
*
|
|
|
|
* @class AnimationFrame
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Animations
|
2018-02-07 15:27:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {string} textureKey - The key of the Texture this AnimationFrame uses.
|
2018-03-20 14:58:02 +00:00
|
|
|
* @param {(string|integer)} textureFrame - The key of the Frame within the Texture that this AnimationFrame uses.
|
2018-02-07 15:27:21 +00:00
|
|
|
* @param {integer} index - The index of this AnimationFrame within the Animation sequence.
|
|
|
|
* @param {Phaser.Textures.Frame} frame - A reference to the Texture Frame this AnimationFrame uses for rendering.
|
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
var AnimationFrame = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function AnimationFrame (textureKey, textureFrame, index, frame)
|
|
|
|
{
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* The key of the Texture this AnimationFrame uses.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#textureKey
|
|
|
|
* @type {string}
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.textureKey = textureKey;
|
2018-01-21 13:01:38 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* The key of the Frame within the Texture that this AnimationFrame uses.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#textureFrame
|
2018-03-20 14:58:02 +00:00
|
|
|
* @type {(string|integer)}
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.textureFrame = textureFrame;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* The index of this AnimationFrame within the Animation sequence.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#index
|
|
|
|
* @type {integer}
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.index = index;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* A reference to the Texture Frame this AnimationFrame uses for rendering.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#frame
|
|
|
|
* @type {Phaser.Textures.Frame}
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.frame = frame;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* Is this the first frame in an animation sequence?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#isFirst
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.isFirst = false;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* Is this the last frame in an animation sequence?
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#isLast
|
|
|
|
* @type {boolean}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default false
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.isLast = false;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* A reference to the AnimationFrame that comes before this one in the animation, if any.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#prevFrame
|
|
|
|
* @type {?Phaser.Animations.AnimationFrame}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default null
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.prevFrame = null;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* A reference to the AnimationFrame that comes after this one in the animation, if any.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#nextFrame
|
|
|
|
* @type {?Phaser.Animations.AnimationFrame}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default null
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.nextFrame = null;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* Additional time (in ms) that this frame should appear for during playback.
|
|
|
|
* The value is added onto the msPerFrame set by the animation.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#duration
|
|
|
|
* @type {number}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 0
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.duration = 0;
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* What % through the animation does this frame come?
|
|
|
|
* This value is generated when the animation is created and cached here.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @name Phaser.Animations.AnimationFrame#progress
|
|
|
|
* @type {number}
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default 0
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-24 23:50:46 +00:00
|
|
|
* @since 3.0.0
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
this.progress = 0;
|
|
|
|
},
|
|
|
|
|
2018-01-24 23:50:46 +00:00
|
|
|
/**
|
|
|
|
* Generates a JavaScript object suitable for converting to JSON.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.AnimationFrame#toJSON
|
|
|
|
* @since 3.0.0
|
2018-03-19 16:55:21 +00:00
|
|
|
*
|
|
|
|
* @return {JSONAnimationFrame} The AnimationFrame data.
|
2018-01-24 23:50:46 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
toJSON: function ()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
key: this.textureKey,
|
|
|
|
frame: this.textureFrame,
|
2018-01-24 23:50:46 +00:00
|
|
|
duration: this.duration
|
2017-10-13 10:56:52 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-01-24 23:50:46 +00:00
|
|
|
/**
|
|
|
|
* Destroys this object by removing references to external resources and callbacks.
|
|
|
|
*
|
|
|
|
* @method Phaser.Animations.AnimationFrame#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.frame = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AnimationFrame;
|