2018-01-16 13:04:35 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-10-13 10:56:52 +00:00
|
|
|
|
|
|
|
var AnimationFrame = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2018-01-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* 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.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
|
|
|
* @class AnimationFrame
|
2018-01-24 23:50:46 +00:00
|
|
|
* @memberOf Phaser.Animations
|
2018-01-21 13:01:38 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-01-24 23:50:46 +00:00
|
|
|
* @param {string} textureKey - The key of the Texture this AnimationFrame uses.
|
|
|
|
* @param {string|integer} textureFrame - The key of the Frame within the Texture that this AnimationFrame uses.
|
|
|
|
* @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.
|
2018-01-21 13:01:38 +00:00
|
|
|
*/
|
2017-10-13 10:56:52 +00:00
|
|
|
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
|
|
|
*
|
|
|
|
* @property {string} textureKey
|
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-01-24 23:50:46 +00:00
|
|
|
* @property {string|integer} textureFrame
|
|
|
|
* @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
|
|
|
*
|
|
|
|
* @property {integer} index
|
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
|
|
|
*
|
|
|
|
* @property {Phaser.Textures.Frame} 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
|
|
|
*
|
|
|
|
* @property {boolean} isFirst
|
|
|
|
* @default false
|
2018-01-24 23:50:46 +00:00
|
|
|
* @readOnly
|
|
|
|
* @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
|
|
|
*
|
|
|
|
* @property {boolean} isLast
|
|
|
|
* @default false
|
2018-01-24 23:50:46 +00:00
|
|
|
* @readOnly
|
|
|
|
* @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-01-24 23:50:46 +00:00
|
|
|
* @property {?Phaser.Animations.AnimationFrame} prevFrame
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default null
|
2018-01-24 23:50:46 +00:00
|
|
|
* @readOnly
|
|
|
|
* @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-01-24 23:50:46 +00:00
|
|
|
* @property {?Phaser.Animations.AnimationFrame} nextFrame
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default null
|
2018-01-24 23:50:46 +00:00
|
|
|
* @readOnly
|
|
|
|
* @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
|
|
|
*
|
|
|
|
* @property {number} duration
|
|
|
|
* @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
|
|
|
*
|
|
|
|
* @property {number} progress
|
|
|
|
* @default 0
|
2018-01-24 23:50:46 +00:00
|
|
|
* @readOnly
|
|
|
|
* @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-21 13:01:38 +00:00
|
|
|
/**
|
2018-01-24 23:50:46 +00:00
|
|
|
* A frame specific callback, invoked if this frame gets displayed and the callback is set.
|
2018-01-21 13:01:38 +00:00
|
|
|
*
|
2018-01-24 23:50:46 +00:00
|
|
|
* @property {?function} onUpdate
|
2018-01-21 13:01:38 +00:00
|
|
|
* @default null
|
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.onUpdate = null;
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @return {object} The AnimationFrame data.
|
|
|
|
*/
|
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;
|
|
|
|
this.onUpdate = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AnimationFrame;
|