2017-04-04 15:32:33 +00:00
|
|
|
var GetObjectValue = require('../../utils/object/GetObjectValue');
|
|
|
|
var GetFrames = require('./GetFrames');
|
|
|
|
|
2017-04-04 15:50:28 +00:00
|
|
|
var Animation = function (manager, key, config)
|
2017-04-04 15:32:33 +00:00
|
|
|
{
|
|
|
|
this.manager = manager;
|
|
|
|
|
2017-04-04 15:50:28 +00:00
|
|
|
this.key = key;
|
|
|
|
|
2017-04-04 15:32:33 +00:00
|
|
|
// frames: [
|
|
|
|
// { key: textureKey, frame: textureFrame },
|
|
|
|
// { key: textureKey, frame: textureFrame, duration: float },
|
|
|
|
// { key: textureKey, frame: textureFrame, onUpdate: function }
|
|
|
|
// ],
|
|
|
|
// framerate: integer,
|
|
|
|
// duration: float (seconds, optional, ignored if framerate is set),
|
|
|
|
// skipMissedFrames: boolean,
|
|
|
|
// delay: integer
|
|
|
|
// repeat: -1 = forever, otherwise integer
|
|
|
|
// repeatDelay: integer
|
|
|
|
// yoyo: boolean,
|
|
|
|
// onStart: function
|
|
|
|
// onRepeat: function
|
|
|
|
// onComplete: function,
|
|
|
|
|
2017-04-04 15:50:28 +00:00
|
|
|
this.frames = [];
|
|
|
|
|
|
|
|
// Extract all the frame data into the frames array
|
|
|
|
GetFrames(this, GetObjectValue(config, 'frames', []), this.frames);
|
2017-04-04 15:32:33 +00:00
|
|
|
|
|
|
|
this.framerate = GetObjectValue(config, 'framerate', 24);
|
|
|
|
|
|
|
|
this.duration = GetObjectValue(config, 'duration', null);
|
|
|
|
|
|
|
|
if (this.duration === null)
|
|
|
|
{
|
|
|
|
this.duration = this.framerate * this.frames.length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Duration controls framerate
|
|
|
|
}
|
|
|
|
|
|
|
|
this.skipMissedFrames = GetObjectValue(config, 'skipMissedFrames', true);
|
|
|
|
|
|
|
|
// Delay before starting playback (in seconds)
|
|
|
|
this.delay = GetObjectValue(config, 'delay', 0);
|
|
|
|
|
|
|
|
this.repeat = GetObjectValue(config, 'repeat', 0);
|
|
|
|
|
|
|
|
this.repeatDelay = GetObjectValue(config, 'repeatDelay', 0);
|
|
|
|
|
|
|
|
this.yoyo = GetObjectValue(config, 'yoyo', false);
|
|
|
|
|
|
|
|
this.onStart = GetObjectValue(config, 'onStart', false);
|
|
|
|
this.onRepeat = GetObjectValue(config, 'onRepeat', false);
|
|
|
|
this.onComplete = GetObjectValue(config, 'onComplete', false);
|
|
|
|
this.onStop = GetObjectValue(config, 'onStop', false);
|
|
|
|
};
|
|
|
|
|
|
|
|
Animation.prototype.constructor = Animation;
|
|
|
|
|
|
|
|
Animation.prototype = {
|
|
|
|
|
|
|
|
start: function ()
|
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function (elapsed)
|
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
stop: function ()
|
|
|
|
{
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Animation;
|