boolean
or double
-value inputs, or firing trigger inputs. The effects of these will be dependent on how the state machine has been configured in the editor.stateMachineName
on the Rive component to play a single state machine.stateMachineName
when instantiating the RiveViewModel
.play
, pause
, and stop
) to control state machine playback, as long as you set the isStateMachine
attribute to true
.onLoad
callback that's run when the Rive file is loaded and ready for use. We use this callback to ensure that the state machine is instantiated when we query for inputs.stateMachineInputs
function on the Rive object to retrieve the inputs. Each input will have a name and type. There are three types:StateMachineInputType.Trigger
which has a fire()
functionStateMachineInputType.Number
which has a value
number propertyStateMachineInputType.Boolean
which has a value
boolean propertyonStateChange
provides an event
parameter that gives us the string name(s) of the current state(s):useStateMachineInput
hook to make the process of retrieving a state machine input much simpler than that of the basic web runtime.Trigger
input from a named state machine. The three types of inputs are:StateMachineInputType.Trigger
which has a fire()
functionStateMachineInputType.Number
which has a value
number propertyStateMachineInputType.Boolean
which has a value
boolean propertyvalue
stateChange
output will display the list of state changed during the same frame.rivInput
:change
Ouput.Rive
component, including setting input values/triggering for state machines. In this case, there is no need to acquire an instance of an input. Simply set the input state from the Rive ref
or fire an input state.RiveAnimation
widget provides a callback onInit(Artboard artboard)
that is called when the Rive file has loaded and is initialized for playback:onInit
callback, you can create an instance of a StateMachineController
and then retrieve the inputs you're interested in by their name. Specific inputs can be retrieved using findInput()
or all inputs with the inputs
property.bump
input is retrieved, which is an SMITrigger
. This type of input has a fire()
method to activate the trigger. There are two other input types: SMIBool
and SMINumber
. These both have a value
property that can get and set the value.RiveAnimation
is tapped, it fires the bump
input trigger and the state machine reacts appropriately.StateMachineController
. The callback has the name of the state machine and the name of the animation associated with the state transitioned to:RiveViewModel
instantiated in the View class..setInput()
inputName
(String) - Name of the input on a state machine to set a value forvalue
(Bool, Float, or Double) - value to set for the associated inputName
triggerInput()
inputName
(String) - Name of the input on a state machine to trigger
RiveViewModel
. If provided, these delegate functions will be fired whenever a matching event is triggered to be able to hook into and listen for certain events in the Rive animation cycle.RivePlayerDelegate
- Hook into animation and state machine lifecycle eventsplayer
: (loopedWithModel riveModel: RiveModel?, type: Int) {}
player
: (playedWithModel riveModel: RiveModel?) {}
player
: (pausedWithModel riveModel: RiveModel?) {}
player
: (stoppedWithModel riveModel: RiveModel?) {}
RiveStateMachineDelegate
- Hook into state changes on a state machine lifecyclestateMachine
: (_ stateMachine: RiveStateMachineInstance, didStateChange stateName: String) {}
RiveViewModel
, implementing as many protocols as are needed. Below is an example of how to customize a RiveViewModel's implementation of the RivePlayerDelegate
:rive-android
runtime, use the view to set values on a state machine input. In this case, there is no need to grab references to state machine input instances to set values..setNumberState(stateMachineName: String, inputName: String, value: Float)
.setBooleanState(stateMachineName: String, inputName: String, value: Boolean)
.fireState(stateMachineName: String, inputName: String)
Listener
to register on your animation view, you can add the following callback, where you'll receive the name of the state machine, and the state it transitions to: