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
|
|
|
// Extract all the frame data into the frames array
|
2017-04-04 22:59:37 +00:00
|
|
|
|
|
|
|
this.frames = GetFrames(manager.textureManager, GetObjectValue(config, '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 = {
|
|
|
|
|
2017-04-04 22:59:37 +00:00
|
|
|
load: function (component, startFrame)
|
2017-04-04 15:32:33 +00:00
|
|
|
{
|
2017-04-04 22:59:37 +00:00
|
|
|
if (startFrame >= this.frames.length)
|
|
|
|
{
|
|
|
|
startFrame = 0;
|
|
|
|
}
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2017-04-04 22:59:37 +00:00
|
|
|
component.currentAnim = this;
|
|
|
|
component.currentFrame = this.frames[startFrame];
|
2017-04-04 15:32:33 +00:00
|
|
|
},
|
|
|
|
|
2017-04-04 22:59:37 +00:00
|
|
|
checkFrame: function (index)
|
2017-04-04 15:32:33 +00:00
|
|
|
{
|
2017-04-04 22:59:37 +00:00
|
|
|
return (index < this.frames.length);
|
2017-04-04 15:32:33 +00:00
|
|
|
},
|
|
|
|
|
2017-04-04 22:59:37 +00:00
|
|
|
setFrame: function (timestamp, child)
|
2017-04-04 15:32:33 +00:00
|
|
|
{
|
2017-04-04 22:59:37 +00:00
|
|
|
// Work out which frame should be set next on the child, and set it
|
|
|
|
|
|
|
|
|
2017-04-04 15:32:33 +00:00
|
|
|
|
2017-04-04 22:59:37 +00:00
|
|
|
return child;
|
2017-04-04 15:32:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Animation;
|