phaser/src/animations/AnimationFrame.js

182 lines
5.3 KiB
JavaScript
Raw Normal View History

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
*/
2018-01-16 13:04:35 +00:00
var Class = require('../utils/Class');
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
2018-12-12 11:56:09 +00:00
* frames in the animation, and index data. It also has the ability to modify the animation timing.
2018-02-07 15:27:21 +00:00
*
* 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.
2020-10-05 07:06:53 +00:00
* @param {boolean} [isKeyFrame=false] - Is this Frame a Keyframe within the Animation?
2018-02-07 15:27:21 +00:00
*/
var AnimationFrame = new Class({
initialize:
2020-10-05 07:06:53 +00:00
function AnimationFrame (textureKey, textureFrame, index, frame, isKeyFrame)
{
2020-10-05 07:06:53 +00:00
if (isKeyFrame === undefined) { isKeyFrame = false; }
2018-01-21 13:01:38 +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}
* @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
*
2018-02-07 15:27:21 +00:00
* @name Phaser.Animations.AnimationFrame#textureFrame
2018-03-20 14:58:02 +00:00
* @type {(string|integer)}
* @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
*
2018-02-07 15:27:21 +00:00
* @name Phaser.Animations.AnimationFrame#index
* @type {integer}
* @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
*
2018-02-07 15:27:21 +00:00
* @name Phaser.Animations.AnimationFrame#frame
* @type {Phaser.Textures.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
*
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
* @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
*
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
* @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
*
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
* @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
*
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
* @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
*
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
* @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
*
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
* @since 3.0.0
2018-01-21 13:01:38 +00:00
*/
this.progress = 0;
2020-10-05 07:06:53 +00:00
/**
* Is this Frame a KeyFrame within the Animation?
*
* @name Phaser.Animations.AnimationFrame#isKeyFrame
* @type {boolean}
* @since 3.50.0
*/
this.isKeyFrame = isKeyFrame;
},
/**
* 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
*
2019-05-09 10:46:07 +00:00
* @return {Phaser.Types.Animations.JSONAnimationFrame} The AnimationFrame data.
*/
toJSON: function ()
{
return {
key: this.textureKey,
frame: this.textureFrame,
2020-10-05 07:06:53 +00:00
duration: this.duration,
keyframe: this.isKeyFrame
};
},
/**
* 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;
}
});
module.exports = AnimationFrame;