durationfunction advance(self: AnimationExample, seconds: number): boolean
if self.anim
print(self.anim.duration)
end
return true
end
advanceadvance(seconds: number) -> boolean
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
setTimesetTime(time: number) -> ()
function advance(self: AnimationExample, seconds: number): boolean
if self.anim and self.artboardInstance then
-- Set the animation to a specific time in seconds
self.anim:setTime(0.3)
-- Advance the artboard with 0 to propagate changes without double-counting time
self.artboardInstance:advance(0)
end
return true
end
setTimeFramessetTimeFrames(frames: number) -> ()
function advance(self: AnimationExample, seconds: number): boolean
if self.anim and self.artboardInstance then
-- Set the animation to a specific frame
self.anim:setTimeFrames(3)
-- Advance the artboard with 0 to propagate changes without double-counting time
self.artboardInstance:advance(0)
end
return true
end
setTimePercentagesetTimePercentage(percentage: number) -> ()
function advance(self: AnimationExample, seconds: number): boolean
if self.anim and self.artboardInstance then
-- Set the animation to a specific percentage of the duration.
self.anim:setTimePercentage(.5)
-- Advance the artboard with 0 to propagate changes without double-counting time
self.artboardInstance:advance(0)
end
return true
end
Was this page helpful?