Actors are produced from kapiInstance.add()
.
actorInstance.keyframe( keyframeId, stateObj )
String or number. Where in the animation to place this keyframe. Can either be the actual keyframe number, or a valid Kapi time format string (see documentation for gotoFrame()
).
Object. The properties of this keyframed state. Any missing parameters on this keyframe will be inferred from previous keyframes in the animation set for this actor. Individual properties can have tweening formulas applied to them and only them. To do this, pass those properties as Object literals that contain one property. That property's name must be the same as a valid kapi.tween
formula.
var demo = kapi(document.getElementById('myCanvas')), circle1 = demo.add(circle, { name : 'myCircle', x : 50, y : 50, radius : 50, color : '#0f0', easing : 'easeInOutQuad' }); circle1 .keyframe(0, { x: 50, y: 50 }) .keyframe('3s', { x: {easeInSine: 450}, y: {easeOutSine: 250}, color: '#f0f' }).liveCopy('5s', 0);
actorInstance.updateKeyframe( keyframeId, newProps )
Selectively modify the state properties of a keyframe. Properties that are missing from a call to updateKeyframe()
are left unmodified in the keyframe it is modifying. Note! You cannot update the properties of a keyframe that is a liveCopy. You can only update the properties of the original keyframe that it is copying.
String or number. The desired keyframe to remove actorInstance
from, expressed in Kapi time syntax.
Object. The properties on the keyframe to be updated and their values.
actorInstance.remove( keyframeId )
Cleanly removes actorObj
from keyframeId
, as well as all internal references to it. An error is logged in the JavaScript console if actorObj
does not exist at keyframeId
.
String or number. The desired keyframe to remove actorInstance
from, expressed in Kapi time syntax.
actorInstance.removeAll()
Removes the actor from all keyframes.
actorInstance.liveCopy( keyframeId, keyframeIdToCopy )
Add a keyframe to the animation that is a copy of another keyframe. If the copied keyframe is modified or removed, so is the liveCopy. This is handy for tweening back to the first keyframe state in the animation right before the loop starts over.
String or number. The desired keyframe to remove actorInstance
from, expressed in Kapi time syntax.
String or number. The keyframe identifier of the keyframe to copy. Expressed in Kapi time syntax.
actorInstance.getState()
Get the current state of the actor as it exists in Kapi.
getState
is called.actorInstance.get( prop )
Get the current value of a single state property from the actor.
String. The state property to retrieve. If prop
is "layer," this function will return the layer that this actor is currently in.
prop
is.actorInstance.moveToLayer( layerId )
Change the layer that the actor is currently in. Valid parameters are any layer index between 0 and the max number of layers (inclusive). You can get the upper bound by calling kapiInstance.getNumberOfLayers()
.
Number. The layer to move the actor to.
actorInstance.data( newData )
Store and retrieve arbitrary data on an actor. This data can be anything, in any format.
Any data type. This is the data that will be stored on the actor.
actorInstance.to( duration, stateObj, events )
Creates an Immediate Action and adds it to the Immediate Actions queue. This immediately starts applying a state change over time.
String or number. The length of time to apply the change. This can be either an amount of frames or a period of time, expressed in Kapi time syntax (see documentation for gotoFrame()
).
Object. The state to animate the actor to.
Event handlers to attach to this immediate action. This parameter is optional. In an event handler function, the this
keyword refers to the actor object. Available events:
start
: A function. Fires when the Immediate Action starts.complete
: A function. Fires when the Immediate Action completes.var demo = kapi(document.getElementById('myCanvas')), circle1 = demo.add(circle, { name : 'myCircle', x : 0, y : 0, radius : 50, color : '#00ff00' }); circle1.keyframe(0, { }) .to('2s', { x: '+=100', y: 50, color: '#3f0000' }, { 'start': function () { console.log('Immediate action started!', this); }, 'complete': function () { console.log('Immediate action completed!', this); } });
actorInstance.clearQueue()
Removes any queued Immediate Actions that have not yet begun. This does not cancel or affect the currently executing Immediate Action.
actorInstance.skipToEnd()
Skips to the end of the currently executing Immediate Action. The complete
event is fired, if it was set. The Immediate Action queue is not affected.
actorInstance.endCurrentAction()
Stops and ends the currently executing Immediate Action in its current state. Note: Internally, this method calls actor.skipToEnd()
, so the functionality of that method applies here as well.
actorInstance.params
This is a copy of the parameters that were passed to kapi.add()
when this actor was created.
actorInstance.kapi
This is a reference to the Kapi instance that controls this actor.