Constructor
new Rekapi(contextopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
Object
|
CanvasRenderingContext2D
|
HTMLElement
|
<optional> |
{} |
Sets
|
Members
context :Object|CanvasRenderingContext2D|HTMLElement
The rendering context for an animation.
Type:
-
Object
|CanvasRenderingContext2D
|HTMLElement
renderers :Array.<rekapi.renderer>
Instances of
rekapi.renderer
classes, as inferred by the context
parameter provided to the rekapi.Rekapi
constructor. You can
add more renderers to this list manually; see the Multiple Renderers tutorial for an example.
Type:
-
Array.<rekapi.renderer>
sort :rekapi.actorSortFunction|null
Optional
function for sorting the render order of rekapi.Actor
s. If set,
this is called each frame before the rekapi.Actor
s are rendered.
If not set, rekapi.Actor
s will render in the order they were
added via rekapi.Rekapi#addActor
.
The following example assumes that all rekapi.Actor
s are circles
that have a radius
rekapi.KeyframeProperty
. The circles will
be rendered in order of the value of their radius
, from smallest to
largest. This has the effect of layering larger circles on top of
smaller circles, thus giving a sense of perspective.
const rekapi = new Rekapi();
rekapi.sort = actor => actor.get().radius;
Type:
-
rekapi.actorSortFunction
|null
Methods
addActor(actoropt) → {rekapi.Actor}
Add a rekapi.Actor
to the animation. Decorates the added rekapi.Actor
with a reference to this rekapi.Rekapi
instance as
rekapi.Actor#rekapi
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
actor |
rekapi.Actor
|
Object
|
<optional> |
{} |
If this is an |
Fires:
exportTimeline(configopt) → {rekapi.timelineData}
Export the timeline to a JSON.stringify
-friendly Object
.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object
|
<optional> |
|
getActor(actorId) → {rekapi.Actor}
Parameters:
Name | Type | Description |
---|---|---|
actorId |
number
|
Returns:
- Type:
-
rekapi.Actor
A reference to an actor from the animation by its
id
. You can use rekapi.Rekapi#getActorIds
to get a list of IDs
for all actors in the animation.
getActorCount() → {number}
getActorIds() → {Array.<number>}
getAllActors() → {Array.<rekapi.Actor>}
getAnimationLength() → {number}
Returns:
- Type:
-
number
The length of the animation timeline, in milliseconds.
getEventNames() → {Array.<string>}
Returns:
- Type:
-
Array.<string>
The list of event names that this Rekapi instance supports.
getLastMillisecondUpdated() → {number}
Returns:
- Type:
-
number
The millisecond that was last rendered.
getLastPositionUpdated() → {number}
Returns:
- Type:
-
number
The normalized timeline position (between 0 and 1) that was last rendered.
getRendererInstance(rendererConstructor) → {rekapi.renderer|undefined}
Get a reference to a rekapi.renderer
that was initialized for this
animation.
Parameters:
Name | Type | Description |
---|---|---|
rendererConstructor |
rekapi.renderer
|
The type of |
importTimeline(rekapiData)
Import data that was created by rekapi.Rekapi#exportTimeline
.
This sets up all actors, keyframes, and custom easing curves specified in
the rekapiData
parameter. These two methods collectively allow you
serialize an animation (for sending to a server for persistence, for
example) and later recreating an identical animation.
Parameters:
Name | Type | Description |
---|---|---|
rekapiData |
rekapi.timelineData
|
Any object that has the same data
format as the object generated from |
isPaused() → {boolean}
Returns:
- Type:
-
boolean
Whether or not the animation is paused (meaning not playing or stopped).
isPlaying() → {boolean}
Returns:
- Type:
-
boolean
Whether or not the animation is playing (meaning not paused or stopped).
isStopped() → {boolean}
Returns:
- Type:
-
boolean
Whether or not the animation is stopped (meaning not playing or paused).
moveActorToPosition(actor, layer) → {rekapi.Rekapi}
Move a rekapi.Actor
around within the internal render order list.
By default, a rekapi.Actor
is rendered in the order it was added
with rekapi.Rekapi#addActor
.
This method has no effect if rekapi.Rekapi#sort
is set.
Parameters:
Name | Type | Description |
---|---|---|
actor |
rekapi.Actor
|
|
layer |
number
|
This should be within |
Returns:
- Type:
-
rekapi.Rekapi
off(eventName, handleropt) → {rekapi.Rekapi}
Unbind one or more handlers from a Rekapi event.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventName |
string
|
Valid values correspond to the list under
|
|
handler |
rekapi.eventHandler
|
<optional> |
A reference to the |
Returns:
- Type:
-
rekapi.Rekapi
on(eventName, handler) → {rekapi.Rekapi}
Bind a rekapi.eventHandler
function to a Rekapi event.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
string
|
|
handler |
rekapi.eventHandler
|
The event handler function. |
Returns:
- Type:
-
rekapi.Rekapi
pause() → {rekapi.Rekapi}
Pause the animation. A "paused" animation can be resumed from where it
left off with rekapi.Rekapi#play
.
Fires:
Returns:
- Type:
-
rekapi.Rekapi
play(iterationsopt) → {rekapi.Rekapi}
Play the animation.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterations |
number
|
<optional> |
-1 |
If omitted, the animation will loop endlessly. |
Fires:
Returns:
- Type:
-
rekapi.Rekapi
playFrom(millisecond, iterationsopt) → {rekapi.Rekapi}
Move to a specific millisecond on the timeline and play from there.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
millisecond |
number
|
||
iterations |
number
|
<optional> |
Works as it does in |
Returns:
- Type:
-
rekapi.Rekapi
playFromCurrent(iterationsopt) → {rekapi.Rekapi}
Play from the last frame that was rendered with rekapi.Rekapi#update
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
iterations |
number
|
<optional> |
Works as it does in |
Returns:
- Type:
-
rekapi.Rekapi
removeActor(actor) → {rekapi.Actor}
Remove an actor from the animation. This does not destroy the actor, it
only removes the link between it and this rekapi.Rekapi
instance.
This method calls the actor's rekapi.Actor#teardown
method, if
defined.
Parameters:
Name | Type | Description |
---|---|---|
actor |
rekapi.Actor
|
Fires:
removeAllActors() → {Array.<rekapi.Actor>}
Remove all rekapi.Actor
s from the animation.
stop() → {rekapi.Rekapi}
Stop the animation. A "stopped" animation will start from the beginning
if rekapi.Rekapi#play
is called.
Fires:
Returns:
- Type:
-
rekapi.Rekapi
trigger(eventName, dataopt) → {rekapi.Rekapi}
Manually fire a Rekapi event, thereby calling all rekapi.eventHandler
s bound to that event.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eventName |
string
|
The name of the event to trigger. |
|
data |
any
|
<optional> |
Optional data to provide to the |
Fires:
- event:*
Returns:
- Type:
-
rekapi.Rekapi
update(millisecondopt, doResetLaterFnKeyframesopt) → {rekapi.Rekapi}
Render an animation frame at a specific point in the timeline.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
millisecond |
number
|
<optional> |
this._lastUpdatedMillisecond |
The point in the timeline at which to render. If omitted, this renders the last millisecond that was rendered (it's a re-render). |
doResetLaterFnKeyframes |
boolean
|
<optional> |
false |
If |
Fires:
Returns:
- Type:
-
rekapi.Rekapi