Animation Playback
Playing and pausing animations.
Rive lets you specify what artboard to use, what animations and state machines to mix and play and control the play/pause state of each animation.
The term animations may collectively refer to both animations and state machines. In this section, we explore how to deal with specific animation playback, rather than state machines.
If you are trying to coordinate multiple animations’ playback at runtime, consider using a state machine instead to do this for you!
Choosing an artboard
When a Rive object is instantiated, the artboard to use can be specified. If no artboard is given, the default artboard is used. Only one artboard can be used at a time.
Choosing starting animations
Starting animations can also be chosen when Rive is instantiated. The first animation on the artboard may play if one is not provided, or a state machine is not set.
Controlling playback
Playback of each animation and state machine can be separately controlled. You can play and pause playback using the play
, pause
and stop
methods, either passing in the names of the animations you want to affect or passing in nothing which will affect all instanced animations.
Invoking Playback Controls
With the web runtime, you can provide callback functions to receive notification when certain animation events have occurred:
onLoad
when a rive file has been loaded and initialized; it’s now ready for playbackonPlay
when one or more animations play; provides a list of animationsonPause
when one or more animations pause; provides a list of animationsonStop
when one or more animations are stopped; provides a list of animationsonLoop
when an animation loops; provides the animation name
See the following codepen link to try out the below code: https://codepen.io/zplata/pen/yLPqLRa
Was this page helpful?