phaser/src/animations/AnimationFrame.js

163 lines
4.5 KiB
JavaScript
Raw Normal View History

2018-01-16 13:04:35 +00:00
var Class = require('../utils/Class');
var AnimationFrame = new Class({
initialize:
2018-01-21 13:01:38 +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
* @memberOf Phaser.Animations
2018-01-21 13:01:38 +00:00
* @constructor
* @since 3.0.0
*
* @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
*/
function AnimationFrame (textureKey, textureFrame, index, frame)
{
2018-01-21 13:01:38 +00:00
/**
* The key of the Texture this AnimationFrame uses.
2018-01-21 13:01:38 +00:00
*
* @property {string} textureKey
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.textureKey = textureKey;
2018-01-21 13:01:38 +00:00
/**
* The key of the Frame within the Texture that this AnimationFrame uses.
2018-01-21 13:01:38 +00:00
*
* @property {string|integer} textureFrame
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.textureFrame = textureFrame;
2018-01-21 13:01:38 +00:00
/**
* The index of this AnimationFrame within the Animation sequence.
2018-01-21 13:01:38 +00:00
*
* @property {integer} index
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.index = index;
2018-01-21 13:01:38 +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
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.frame = frame;
2018-01-21 13:01:38 +00:00
/**
* Is this the first frame in an animation sequence?
2018-01-21 13:01:38 +00:00
*
* @property {boolean} isFirst
* @default false
* @readOnly
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.isFirst = false;
2018-01-21 13:01:38 +00:00
/**
* Is this the last frame in an animation sequence?
2018-01-21 13:01:38 +00:00
*
* @property {boolean} isLast
* @default false
* @readOnly
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.isLast = false;
2018-01-21 13:01:38 +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
*
* @property {?Phaser.Animations.AnimationFrame} prevFrame
2018-01-21 13:01:38 +00:00
* @default null
* @readOnly
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.prevFrame = null;
2018-01-21 13:01:38 +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
*
* @property {?Phaser.Animations.AnimationFrame} nextFrame
2018-01-21 13:01:38 +00:00
* @default null
* @readOnly
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.nextFrame = null;
2018-01-21 13:01:38 +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
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.duration = 0;
2018-01-21 13:01:38 +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
* @readOnly
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.progress = 0;
2018-01-21 13:01:38 +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
*
* @property {?function} onUpdate
2018-01-21 13:01:38 +00:00
* @default null
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.onUpdate = null;
},
/**
* Generates a JavaScript object suitable for converting to JSON.
*
* @method Phaser.Animations.AnimationFrame#toJSON
* @since 3.0.0
*
* @return {object} The AnimationFrame data.
*/
toJSON: function ()
{
return {
key: this.textureKey,
frame: this.textureFrame,
duration: this.duration
};
},
/**
* Destroys this object by removing references to external resources and callbacks.
*
* @method Phaser.Animations.AnimationFrame#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.frame = undefined;
this.onUpdate = undefined;
}
});
module.exports = AnimationFrame;