Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
251 lines (175 sloc) 4.85 KB

Kapi

Kapi

/**
 * @param {Object=} opt_config
 *   @param {number=} fps
 *   @param {Object=} context
 * @constructor
 */
Kapi (opt_config)

Create a Kapi instance. Valid properties of opt_config:

  • fps: The frames per second at which the animation updates. The default value is 30.
  • context: The context that the animation will run in. Can be any type of Object; gets used by the renderer and inherited by the Kapi.Actors as they are added to the animation. This isn't always needed, it usually just applies to <canvas> animations. See the documenation on the <canvas> extension for more info.

Example

addActor

/**
 * @param {Kapi.Actor} actor
 * @returns {Kapi}
 */
Kapi.prototype.addActor (actor)

Add a Kapi.Actor to a Kapi instance.

Example

getActor

/**
 * @param {number} actorId
 * @returns {Kapi.Actor}
 */
Kapi.prototype.getActor (actorId)

Retrieve an Actor from the Kapi instance by its ID. All Actor's have an id property.

Example

getAllActors

/**
 * @returns {Object}
 */
Kapi.prototype.getAllActors ()

Retrieve all Actors in a Kapi instance as an Object. Actor IDs correspond to the property names of the returned Object.

Example

getActorIds

/**
 * @returns {Array}
 */
Kapi.prototype.getActorIds ()

Retrieve the IDs of all Actors in a Kapi instance as an Array.

Example

removeActor

/**
 * @param {Kapi.Actor} actor
 * @returns {Kapi}
 */
Kapi.prototype.removeActor (actor)

Remove actor from the animation. This does not destroy actor, it only removes the link between actor and the Kapi instance.

Example

isPlaying

/**
 * @returns {boolean}
 */
Kapi.prototype.isPlaying ()

Return whether or not the animation is playing (meaning not paused or stopped).

Example

animationLength

/**
 * @returns {number}
 */
Kapi.prototype.animationLength ()

Return the length of the animation, in milliseconds.

Example

lastPositionUpdated

/**
 * @returns {number}
 */
Kapi.prototype.lastPositionUpdated ()

Return the normalized (between 0 and 1) timeline position that was last calculated.

Example

actorCount

/**
 * @returns {number}
 */
Kapi.prototype.actorCount ()

Return the number of Actors in the animation.

Example

framerate

/**
 * @param {number=} opt_newFramerate
 * @returns {number}
 */
Kapi.prototype.framerate (opt_newFramerate)

Get and optionally set the framerate of the animation. There's generally no point in going above 60.

Example

update

/**
 * @param {number=} opt_millisecond
 * @returns {Kapi}
 */
Kapi.prototype.update (opt_millisecond)

Update the position of all the Actors to opt_millisecond. If opt_millisecond is undefined, update to the last milliscond that the animation was updated to (it's a re-update).

Example

exportTimeline

/**
 * @return {Object}
 */
Kapi.prototype.exportTimeline ()

Export a reference-less dump of this Kapi's animation properties and Actors.

Example

on

/**
 * @param {string} eventName
 * @param {function} handler
 * @returns {Kapi}
 */
Kapi.prototype.on (eventName, handler)

Bind an handler function to a Kapi event. Possible events include:

  • animationComplete: Fires when all animations loops have completed.
  • playStateChange: Fires when the animation is played, paused, or stopped.
  • play: Fires when the animation is play()ed.
  • pause: Fires when the animation is pause()d.
  • stop: Fires when the animation is stop()ped.
  • beforeUpdate: Fires each frame before all Actors are updated.
  • afterUpdate: Fires each frame after all Actors are updated.
  • addActor: Fires when an Actor is added.
  • removeActor: Fires when an Actor is removed.

Example

off

/**
 * @param {string} eventName
 * @param {function=} opt_handler
 * @returns {Kapi}
 */
Kapi.prototype.off (eventName, opt_handler)

Unbind opt_handler from a Kapi event. If opt_handler is omitted, all handler functions bound to eventName are unbound. Valid events correspond to the list under bind().

Example

Something went wrong with that request. Please try again.