2017-04-04 22:59:16 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-05-02 23:54:09 +00:00
|
|
|
var Components = require('./animation/');
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-05-02 15:49:48 +00:00
|
|
|
// Game Object Animation Controller
|
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
var Animation = new Class({
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
initialize:
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
function Animation (parent)
|
2017-04-05 01:06:28 +00:00
|
|
|
{
|
2017-04-06 23:07:20 +00:00
|
|
|
// Sprite / Game Object
|
|
|
|
this.parent = parent;
|
2017-04-05 01:06:28 +00:00
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
this.animationManager = parent.scene.sys.anims;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2017-05-02 15:02:49 +00:00
|
|
|
this.animationManager.events.once('REMOVE_ANIMATION_EVENT', this.remove.bind(this));
|
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this.isPlaying = false;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Reference to the Phaser.Animation object
|
|
|
|
this.currentAnim = null;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Reference to the Phaser.AnimationFrame object
|
|
|
|
this.currentFrame = null;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Animation specific values
|
|
|
|
// -------------------------
|
2017-04-05 01:06:28 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Scale the time (make it go faster / slower)
|
2017-04-06 23:34:06 +00:00
|
|
|
// Factor that's used to scale time where 1 = normal speed (the default), 0.5 = half speed, 2 = double speed, etc.
|
|
|
|
this._timeScale = 1;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// The frame rate of playback in frames per second (default 24 if duration is null)
|
|
|
|
this.frameRate = 0;
|
2017-04-05 00:15:53 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// How long the animation should play for. If framerate is set it overrides this value
|
|
|
|
// otherwise framerate is derived from duration
|
|
|
|
this.duration = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// ms per frame (without including frame specific modifiers)
|
|
|
|
this.msPerFrame = 0;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Skip frames if the time lags, or always advanced anyway?
|
|
|
|
this.skipMissedFrames = true;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Delay before starting playback (in seconds)
|
2017-04-06 23:29:20 +00:00
|
|
|
this._delay = 0;
|
2017-04-05 03:18:08 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Number of times to repeat the animation (-1 for infinity)
|
2017-04-06 23:29:20 +00:00
|
|
|
this._repeat = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Delay before the repeat starts (in seconds)
|
2017-04-06 23:29:20 +00:00
|
|
|
this._repeatDelay = 0;
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Should the animation yoyo? (reverse back down to the start) before repeating?
|
2017-04-06 23:29:20 +00:00
|
|
|
this._yoyo = false;
|
2017-04-05 00:15:53 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Playhead values
|
|
|
|
// ---------------
|
2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
// Move the playhead forward (true) or in reverse (false)
|
2017-04-05 01:06:28 +00:00
|
|
|
this.forward = true;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this.accumulator = 0;
|
|
|
|
this.nextTick = 0;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this.repeatCounter = 0;
|
2017-04-05 23:58:48 +00:00
|
|
|
|
|
|
|
this.pendingRepeat = false;
|
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this._paused = false;
|
|
|
|
this._wasPlaying = false;
|
2017-04-10 15:27:32 +00:00
|
|
|
|
|
|
|
this._callbackArgs = [ parent, null ];
|
|
|
|
this._updateParams = [];
|
2017-04-05 23:58:48 +00:00
|
|
|
},
|
|
|
|
|
2017-05-02 15:02:49 +00:00
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2017-04-06 23:29:20 +00:00
|
|
|
delay: Components.Delay,
|
2017-04-06 23:07:20 +00:00
|
|
|
delayedPlay: Components.DelayedPlay,
|
2017-06-26 13:52:58 +00:00
|
|
|
getCurrentKey: Components.GetCurrentKey,
|
2017-04-06 23:07:20 +00:00
|
|
|
load: Components.Load,
|
|
|
|
pause: Components.Pause,
|
|
|
|
paused: Components.Paused,
|
|
|
|
play: Components.Play,
|
|
|
|
progress: Components.Progress,
|
2017-05-02 15:02:49 +00:00
|
|
|
remove: Components.Remove,
|
2017-04-06 23:29:20 +00:00
|
|
|
repeat: Components.Repeat,
|
|
|
|
repeatDelay: Components.RepeatDelay,
|
2017-04-06 23:07:20 +00:00
|
|
|
restart: Components.Restart,
|
|
|
|
resume: Components.Resume,
|
|
|
|
stop: Components.Stop,
|
2017-04-06 23:34:06 +00:00
|
|
|
timeScale: Components.TimeScale,
|
2017-04-06 23:07:20 +00:00
|
|
|
totalFrames: Components.TotalFrames,
|
|
|
|
totalProgress: Components.TotalProgress,
|
|
|
|
update: Components.Update,
|
|
|
|
updateFrame: Components.UpdateFrame,
|
|
|
|
yoyo: Components.Yoyo
|
2017-04-05 14:27:26 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-04 22:59:16 +00:00
|
|
|
module.exports = Animation;
|