type AnimationExample = {
-- Artboard input, assigned in the Rive editor by the designer
character: Input<Artboard<nil>>,
-- The live instance and its animation
artboardInstance: Artboard<nil>?,
anim: Animation?,
}
function init(self: AnimationExample, context: Context): boolean
self.artboardInstance = self.character:instance()
if self.artboardInstance then
self.anim = self.artboardInstance:animation('Idle')
end
return true
end
function advance(self: AnimationExample, seconds: number): boolean
if self.anim and self.artboardInstance then
-- Advance the animation to apply keyframe values to the artboard
self.anim:advance(seconds * 2)
-- Advance the artboard with 0 to propagate changes without double-counting time
self.artboardInstance:advance(0)
end
return true
end
function draw(self: AnimationExample, renderer: Renderer)
if self.artboardInstance then
renderer:save()
self.artboardInstance:draw(renderer)
renderer:restore()
end
end
return function(): Node<AnimationExample>
return {
character = late(),
artboardInstance = nil,
anim = nil,
init = init,
advance = advance,
draw = draw,
}
end