Methods
-
on( event, listener )
-
Description
Create an event listenerParameters
Name Type Description eventstring The name of the event to listen for listenerfunction A callback to run when the event is fired. Details
-
removeListener( event, listener )
-
Description
Remove an event listenerParameters
Name Type Description eventstring The name of the event that we are removing a listener from listenerfunction The callback that we are removing Details
-
once( event, listener )
-
Description
Create an event listener that will only fire one time.Parameters
Name Type Description eventstring The name of the event to listen for listenerfunction A callback to run when the event is fired. Details
-
enqueue( options )
-
Description
Add an animation segment to the animation queue (See j5e's Timeline and Tweening Tools for more information)Parameters
Name Type Description optionsobject Animation segment options Name Type Attributes Default Description keyFramesArray.<object> Values for each cuepoint cuePointsArray.<number> <optional> [0, 1] Segment cuepoints from 0-1 durationnumber <optional> 1000 Duration of segment in ms easingfuction <optional> linear() Easing function to use for segment loopboolean <optional> false If true the segment will loop back loopbacknumber <optional> 0 The time to loop back to [0-1] metronomicboolean <optional> false Instead of looping back to the beginning it will reverse direction at the end of the segment currentSpeednumber <optional> 1 The playback speed [0-1] progressnumber <optional> The current progress fpsnumber <optional> 50 Frames per second ratenumber <optional> 20 ms between frames pausedboolean <optional> false Wether the animation is in a paused state onstartfunction <optional> Function to call when the segment starts onpausefunction <optional> Function to call when the segment is paused onstopfunction <optional> Function to call when the segment is stopped oncompletefunction <optional> Function to call when the segment is complete onloopfunction <optional> Function to call when the segment loops Examples
Make a servo "wave"
import Servo from "j5e/servo"; import Animation from "j5e/animation"; const servo = await new Servo(13); const ani = await new Animation(servo); const wave = { duration: 4000, cuePoints: [0, 0.375, 0.625, 1], keyFrames: [0, 135, 45, 180], loop: true, metronomic: true }; ani.enqueue(wave);Details
-
play()
-
Description
Resume play on an animation after it has been paused or stopped.Returns
Examples
Make a servo "wave" for five seconds, pause for one second and then resume waving
import Servo from "j5e/servo"; import Animation from "j5e/animation"; import {timer} from "j5e/fn"; const servo = await new Servo(13); const ani = await new Animation(servo); const wave = { duration: 4000, cuePoints: [0, 0.375, 0.625, 1], keyFrames: [0, 135, 45, 180], loop: true, metronomic: true }; ani.enqueue(wave); timer.setTimeout(function() { ani.pause(); }, 5000); timer.setTimeout(function() { ani.play(); }, 6000);Details
-
pause()
-
Description
Pause animation while maintaining progress, speed and segment queueReturns
Examples
Make a servo "wave" for five seconds, pause for one second and then resume waving
import Servo from "j5e/servo"; import Animation from "j5e/animation"; import {timer} from "j5e/fn"; const servo = await new Servo(13); const ani = await new Animation(servo); const wave = { duration: 4000, cuePoints: [0, 0.375, 0.625, 1], keyFrames: [0, 135, 45, 180], loop: true, metronomic: true }; ani.enqueue(wave); timer.setTimeout(function() { ani.pause(); }, 5000); timer.setTimeout(function() { ani.play(); }, 6000);Details
-
stop()
-
Description
Stop the animation, flushing the segment queueReturns
Examples
Make a servo "wave" for five seconds and then stop, flushing the queue
import Servo from "j5e/servo"; import Animation from "j5e/animation"; import {timer} from "j5e/fn"; const servo = await new Servo(13); const ani = await new Animation(servo); const wave = { duration: 4000, cuePoints: [0, 0.375, 0.625, 1], keyFrames: [0, 135, 45, 180], loop: true, metronomic: true }; ani.enqueue(wave); timer.setTimeout(function() { ani.stop(); }, 5000);Details
-
speed( [ speed ] )
-
Description
Get or set the current playback speedParameters
Name Type Attributes Description speedNumber <optional> The desired playback speed (1 = normal) Returns
Examples
Make a servo "wave" for one second, increase the speed, wait another second and decrease the speed for one second and then stop.
import Servo from "j5e/servo"; import Animation from "j5e/animation"; import {timer} from "j5e/fn"; const servo = await new Servo(13); const ani = await new Animation(servo); const wave = { duration: 4000, cuePoints: [0, 0.375, 0.625, 1], keyFrames: [0, 135, 45, 180], loop: true, metronomic: true }; ani.enqueue(wave); timer.setTimeout(function() { ani.speed(2.0); // Speed up to 2x }, 1000); timer.setTimeout(function() { ani.speed(0.5); // Speed up to 1/2x }, 2000); timer.setTimeout(function() { ani.stop(); // Note, animation speed is still 0.5 }, 3000);Details
