Constructor
new Actor(configopt)
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object
|
<optional> |
{} |
|
Members
context :Object|CanvasRenderingContext2D|HTMLElement|undefined
If this rekapi.Actor was created by or
provided as an argument to rekapi.Rekapi#addActor, then this
member is a reference to that rekapi.Rekapi's rekapi.Rekapi#context.
Type:
-
Object|CanvasRenderingContext2D|HTMLElement|undefined
rekapi :rekapi.Rekapi|undefined
The rekapi.Rekapi instance to which this rekapi.Actor belongs, if
any.
Type:
-
rekapi.Rekapi|undefined
setup :function
Gets called when an actor is
added to an animation by rekapi.Rekapi#addActor.
Type:
-
function
teardown :function
Gets called when an actor is
removed from an animation by rekapi.Rekapi#removeActor.
Type:
-
function
wasActive :boolean
A flag that records whether
this rekapi.Actor had any state in the previous updated cycle.
Handy for immediate-mode renderers (such as rekapi.CanvasRenderer) to prevent unintended renders after the actor
has no state. Also used to prevent redundant rekapi.keyframeFunction calls.
Type:
-
boolean
Methods
addKeyframeProperty(keyframeProperty) → {rekapi.Actor}
Associate a rekapi.KeyframeProperty to this rekapi.Actor.
Updates rekapi.KeyframeProperty#actor to maintain a link between
the two objects. This is a lower-level method and it is generally better
to use rekapi.Actor#keyframe. This is mostly useful for adding a
rekapi.KeyframeProperty back to an actor after it was rekapi.KeyframeProperty#detached.
Parameters:
| Name | Type | Description |
|---|---|---|
keyframeProperty |
rekapi.KeyframeProperty
|
Fires:
- rekapi.event:beforeAddKeyframeProperty
- rekapi.event:addKeyframePropertyTrack
- rekapi.event:addKeyframeProperty
Returns:
- Type:
-
rekapi.Actor
copyKeyframe(copyFrom, copyTo) → {rekapi.Actor}
Copies all of the rekapi.KeyframePropertys from one point on the
actor's timeline to another. This is particularly useful for animating an
actor back to its original position.
actor
.keyframe(0, {
x: 10,
y: 15
}).keyframe(1000, {
x: 50,
y: 75
});
// Return the actor to its original position
actor.copyKeyframe(0, 2000);
Parameters:
| Name | Type | Description |
|---|---|---|
copyFrom |
number
|
The timeline millisecond to copy |
copyTo |
number
|
The timeline millisecond to copy |
Returns:
- Type:
-
rekapi.Actor
exportTimeline(configopt) → {rekapi.actorData}
Export this rekapi.Actor to a JSON.stringify-friendly Object.
Parameters:
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object
|
<optional> |
|
getEnd(trackNameopt) → {number}
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
trackName |
rekapi.KeyframeProperty#name
|
<optional> |
Optionally scope the lookup to a particular keyframe track. |
Returns:
- Type:
-
number
The millisecond of the last state of an actor (the point
in the timeline in which it is done animating). If there are no
keyframes, this is 0.
getKeyframeProperty(property, millisecond) → {rekapi.KeyframeProperty|undefined}
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string
|
The name of the property track. |
millisecond |
number
|
The millisecond of the property in the timeline. |
Returns:
- Type:
-
rekapi.KeyframeProperty|undefined
A rekapi.KeyframeProperty that is stored on the actor, as specified by the
property and millisecond parameters. This is undefined if no
properties were found.
getLength(trackNameopt) → {number}
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
trackName |
rekapi.KeyframeProperty#name
|
<optional> |
Optionally scope the lookup to a particular track. |
Returns:
- Type:
-
number
The length of time in milliseconds that the actor animates for.
getPropertiesInTrack(trackName) → {Array(rekapi.KeyframeProperty)}
Get all of the rekapi.KeyframePropertys for a track.
Parameters:
| Name | Type | Description |
|---|---|---|
trackName |
rekapi.KeyframeProperty#name
|
The track name to query. |
Returns:
- Type:
-
Array(rekapi.KeyframeProperty)
getStart(trackNameopt) → {number}
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
trackName |
rekapi.KeyframeProperty#name
|
<optional> |
Optionally scope the lookup to a particular track. |
Returns:
- Type:
-
number
The millisecond of the first animating state of a rekapi.Actor (for instance, if the first keyframe is later than
millisecond 0). If there are no keyframes, this is 0.
getTrackNames() → {Array.<rekapi.KeyframeProperty#name>}
Returns:
- Type:
-
Array.<rekapi.KeyframeProperty#name>
A list of all the track
names for a rekapi.Actor.
hasKeyframeAt(millisecond, trackNameopt) → {boolean}
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
millisecond |
number
|
Point on the timeline to query. |
|
trackName |
rekapi.KeyframeProperty#name
|
<optional> |
Optionally scope the lookup to a particular track. |
Returns:
- Type:
-
boolean
Whether or not the actor has any rekapi.KeyframePropertys set at millisecond.
importTimeline(actorData)
Import an Object to augment this actor's state. This does not remove keyframe properties before importing new ones.
Parameters:
| Name | Type | Description |
|---|---|---|
actorData |
rekapi.actorData
|
Any object that has the same data
format as the object generated from |
keyframe(millisecond, state, easingopt) → {rekapi.Actor}
Create a keyframe for the actor. The animation timeline begins at 0.
The timeline's length will automatically "grow" to accommodate new
keyframes as they are added.
state should contain all of the properties that define this keyframe's
state. These properties can be any value that can be tweened by
Shifty (numbers,
RGB/hexadecimal color strings, and CSS property strings). state can
also be a function, but
this works differently.
Note: Internally, this creates rekapi.KeyframePropertys and
places them on a "track." Tracks are automatically named to match the
relevant rekapi.KeyframeProperty#names. These rekapi.KeyframePropertys are managed for you by the rekapi.Actor
APIs.
Click to learn about keyframes in depth
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
millisecond |
number
|
Where on the timeline to set the keyframe. |
|
state |
Object
|
rekapi.keyframeFunction
|
The state properties of
the keyframe. If this is an Object, the properties will be interpolated
between this and those of the following keyframe for a given point on the
animation timeline. If this is a function ( |
|
easing |
rekapi.easingOption
|
<optional> |
Optional easing string or Object.
If |
Fires:
Returns:
- Type:
-
rekapi.Actor
modifyKeyframe(millisecond, state, easingopt) → {rekapi.Actor}
Augment the value or easing of the rekapi.KeyframePropertys
at a given millisecond. Any rekapi.KeyframePropertys omitted in
state or easing are not modified.
actor.keyframe(0, {
'x': 10,
'y': 20
}).keyframe(1000, {
'x': 20,
'y': 40
}).keyframe(2000, {
'x': 30,
'y': 60
})
// Changes the state of the keyframe at millisecond 1000.
// Modifies the value of 'y' and the easing of 'x.'
actor.modifyKeyframe(1000, {
'y': 150
}, {
'x': 'easeFrom'
});
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
millisecond |
number
|
|||
state |
Object
|
|||
easing |
Object
|
<optional> |
{} |
Returns:
- Type:
-
rekapi.Actor
modifyKeyframeProperty(property, millisecond, newProperties) → {rekapi.Actor}
Modify a rekapi.KeyframeProperty stored on an actor.
Internally, this calls rekapi.KeyframeProperty#modifyWith and
then performs some cleanup.
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string
|
The name of the |
millisecond |
number
|
The timeline millisecond of the |
newProperties |
Object
|
The properties to augment the |
Returns:
- Type:
-
rekapi.Actor
moveKeyframe(from, to) → {boolean}
Moves all of the rekapi.KeyframePropertys from one point on the
actor's timeline to another. Although this method does error checking for
you to make sure the operation can be safely performed, an effective
pattern is to use rekapi.Actor#hasKeyframeAt to see if there is
already a keyframe at the requested to destination.
Parameters:
| Name | Type | Description |
|---|---|---|
from |
number
|
The millisecond of the keyframe to be moved. |
to |
number
|
The millisecond of where the keyframe should be moved to. |
Returns:
- Type:
-
boolean
Whether or not the keyframe was successfully moved.
removeAllKeyframes() → {rekapi.Actor}
Remove all rekapi.KeyframePropertys set
on the actor.
NOTE: This method does not fire the beforeRemoveKeyframeProperty
or removeKeyframePropertyComplete events. This method is a bulk
operation that is more efficient than calling rekapi.Actor#removeKeyframeProperty many times individually, but
foregoes firing events.
Returns:
- Type:
-
rekapi.Actor
removeKeyframe(millisecond) → {rekapi.Actor}
Remove all rekapi.KeyframePropertys set
on the actor at a given millisecond in the animation.
Parameters:
| Name | Type | Description |
|---|---|---|
millisecond |
number
|
The location on the timeline of the keyframe to remove. |
Fires:
Returns:
- Type:
-
rekapi.Actor
removeKeyframeProperty(property, millisecond) → {rekapi.KeyframeProperty|undefined}
Remove a single rekapi.KeyframeProperty
from the actor.
Parameters:
| Name | Type | Description |
|---|---|---|
property |
string
|
The name of the |
millisecond |
number
|
Where in the timeline the |
Fires:
wait(until) → {rekapi.Actor}
Extend the last state on this actor's timeline to simulate a pause.
Internally, this method copies the final state of the actor in the
timeline to the millisecond defined by until.
Parameters:
| Name | Type | Description |
|---|---|---|
until |
number
|
At what point in the animation the Actor should wait
until (relative to the start of the animation timeline). If this number
is less than the value returned from |
Returns:
- Type:
-
rekapi.Actor