Actor

rekapi. Actor

A rekapi.Actor represents an individual component of an animation. An animation may have one or many rekapi.Actors.

Constructor

new Actor(configopt)

Source:
Parameters:
Name Type Attributes Default Description
config Object <optional>
{}
Name Type Attributes Description
context Object | CanvasRenderingContext2D | HTMLElement <optional>

Sets rekapi.Actor#context.

setup function <optional>

Sets rekapi.Actor#setup.

render rekapi.render <optional>

Sets rekapi.Actor#render.

teardown function <optional>

Sets rekapi.Actor#teardown.

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.

Source:
Type:
  • Object | CanvasRenderingContext2D | HTMLElement | undefined

id :string

The unique ID of this rekapi.Actor.

Source:
Type:
  • string

rekapi :rekapi.Rekapi|undefined

The rekapi.Rekapi instance to which this rekapi.Actor belongs, if any.

Source:
Type:

render :rekapi.render

The function that renders this rekapi.Actor.

Source:
Type:

setup :function

Gets called when an actor is added to an animation by rekapi.Rekapi#addActor.

Source:
Type:
  • function

teardown :function

Gets called when an actor is removed from an animation by rekapi.Rekapi#removeActor.

Source:
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.

Source:
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.

Source:
Parameters:
Name Type Description
keyframeProperty rekapi.KeyframeProperty
Fires:
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);
Source:
Parameters:
Name Type Description
copyFrom number

The timeline millisecond to copy rekapi.KeyframePropertys from.

copyTo number

The timeline millisecond to copy rekapi.KeyframePropertys to.

Returns:
Type:
rekapi.Actor

exportTimeline(configopt) → {rekapi.actorData}

Export this rekapi.Actor to a JSON.stringify-friendly Object.

Source:
Parameters:
Name Type Attributes Description
config Object <optional>
Name Type Attributes Default Description
withId boolean <optional>
false

If true, include internal id values in exported data.

Returns:
Type:
rekapi.actorData

This data can later be consumed by rekapi.Actor#importTimeline.

getEnd(trackNameopt) → {number}

Source:
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}

Source:
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}

Source:
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.

Source:
Parameters:
Name Type Description
trackName rekapi.KeyframeProperty#name

The track name to query.

Returns:
Type:
Array(rekapi.KeyframeProperty)

getStart(trackNameopt) → {number}

Source:
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>}

Source:
Returns:
Type:
Array.<rekapi.KeyframeProperty#name>

A list of all the track names for a rekapi.Actor.

hasKeyframeAt(millisecond, trackNameopt) → {boolean}

Source:
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.

Source:
Parameters:
Name Type Description
actorData rekapi.actorData

Any object that has the same data format as the object generated from rekapi.Actor#exportTimeline.

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

Source:
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 (rekapi.keyframeFunction), it will be called at the keyframe specified by millisecond.

easing string | Object <optional>

Optional easing string or Object. If state is a function, this is ignored.

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'
});
Source:
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.

Source:
Parameters:
Name Type Description
property string

The name of the rekapi.KeyframeProperty to modify.

millisecond number

The timeline millisecond of the rekapi.KeyframeProperty to modify.

newProperties Object

The properties to augment the rekapi.KeyframeProperty with.

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.

Source:
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.

Source:
Returns:
Type:
rekapi.Actor

removeKeyframe(millisecond) → {rekapi.Actor}

Remove all rekapi.KeyframePropertys set on the actor at a given millisecond in the animation.

Source:
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.

Source:
Parameters:
Name Type Description
property string

The name of the rekapi.KeyframeProperty to remove.

millisecond number

Where in the timeline the rekapi.KeyframeProperty to remove is.

Fires:
Returns:
Type:
rekapi.KeyframeProperty | undefined

The removed KeyframeProperty, if one was found.

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.

Source:
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 rekapi.Actor#getLength, this method does nothing.

Returns:
Type:
rekapi.Actor