Kapi
functionKapi()
Rekapi constructor. Valid values for opt_config
are:
- context (Object): The context that the animation will run in. Can be any type of
Object
; gets used by the renderer and inherited by theKapi.Actor
s as they are added to the animation. This isn't always needed, it usually just applies to<canvas>
animations. See the documentation on the<canvas>
extension for more info.
function Kapi (opt_config) {
this.config = opt_config || {};
this.context = this.config.context || {};
this._actors = {};
this._playState = playState.STOPPED;
this._events = {
'animationComplete': []
,'playStateChange': []
,'play': []
,'pause': []
,'stop': []
,'beforeUpdate': []
,'afterUpdate': []
,'addActor': []
,'removeActor': []
};
// How many times to loop the animation before stopping.
this._timesToIterate = -1;
// Millisecond duration of the animation
this._animationLength = 0;
// The setTimeout ID of `tick`
this._loopId = null;
// The UNIX time at which the animation loop started
this._loopTimestamp = null;
// Used for maintaining position when the animation is paused.
this._pausedAtTime = null;
// The last millisecond position that was updated
this._lastUpdatedMillisecond = 0;
_.extend(this.config, opt_config);
this._scheduleUpdate = getUpdateMethod();
this._cancelUpdate = getCancelMethod();
_.each(this._contextInitHook, function (fn) {
fn.call(this);
}, this);
return this;
}
// Decorate the Kapi object with the dependencies so that other modules can
// access them.
Kapi.Tweenable = Tweenable;
Kapi._ = _;