Actor
methodKapi.Actor()
Create a Kapi.Actor
instance. Note that the rest of the API docs for Kapi.Actor
will simply refer to this Object as Actor
.
Valid properties of opt_config
(you can omit the ones you don't need):
- context (Object): The context that this Actor is associated with. If omitted, this Actor gets the
Kapi
instance's context when it is added withKapi#addActor
. - setup (Function): A function that gets called when the
Actor
is added withKapi#addActor
. - update (Function(Object, Object)): A function that gets called every time that the
Actor
's state is updated. It receives two parameters: A reference to theActor
's context and an Object containing the current state properties. - teardown (Function): A function that gets called when the
Actor
is removed withKapi#removeActor
.
Kapi.Actor
does not render to any context. It is a base class. Use the Kapi.CanvasActor
or Kapi.DOMActor
subclasses to render to the screen. You can also make your own rendering subclass - see the source code for the aforementioned examples.
Kapi.Actor = function (opt_config) {
opt_config = opt_config || {};
// Steal the `Tweenable` constructor.
Tweenable.call(this);
_.extend(this, {
'_propertyTracks': {}
,'_timelinePropertyCaches': {}
,'_timelinePropertyCacheIndex': []
,'_keyframeProperties': {}
,'id': _.uniqueId()
,'setup': opt_config.setup || noop
,'update': opt_config.update || noop
,'teardown': opt_config.teardown || noop
,'data': {}
});
if (opt_config.context) {
this.context(opt_config.context);
}
return this;
};
var Actor = Kapi.Actor;
// Kind of a fun way to set up an inheritance chain. `ActorMethods` prevents
// methods on `Actor.prototype` from polluting `Tweenable`'s prototype with
// `Actor` specific methods.
var ActorMethods = function () {};
ActorMethods.prototype = Tweenable.prototype;
Actor.prototype = new ActorMethods();
// But the magic doesn't stop here! `Actor`'s constructor steals the
// `Tweenable` constructor.