2017-04-04 22:59:16 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
var Components = require('../animation/frame/');
|
2017-04-04 22:59:16 +00:00
|
|
|
|
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-04-06 23:07:20 +00:00
|
|
|
this.animationManager = parent.state.sys.anims;
|
2017-04-06 02:45:45 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this.mainloop = parent.state.game.mainloop;
|
2017-04-05 01:06:28 +00:00
|
|
|
|
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)
|
|
|
|
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;
|
2017-04-05 02:22:54 +00:00
|
|
|
|
2017-04-06 23:07:20 +00:00
|
|
|
this.prevTick = 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-05 23:58:48 +00:00
|
|
|
},
|
|
|
|
|
2017-04-06 23:29:20 +00:00
|
|
|
delay: Components.Delay,
|
2017-04-06 23:07:20 +00:00
|
|
|
delayedPlay: Components.DelayedPlay,
|
|
|
|
load: Components.Load,
|
|
|
|
pause: Components.Pause,
|
|
|
|
paused: Components.Paused,
|
|
|
|
play: Components.Play,
|
|
|
|
progress: Components.Progress,
|
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,
|
|
|
|
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;
|