rive-react icon indicating copy to clipboard operation
rive-react copied to clipboard

Get current frameTime or frameCount

Open smblee opened this issue 2 years ago • 1 comments

Hello -- Is there a way to either grab or reactively listen to the current frameTime and/or frameCount?

I tried using the rive.frameCount value and it doesn't seem to be returning what i would expect (the number doesn't continue to increment)

smblee avatar Jul 12 '23 00:07 smblee

Hello! There isn't a way to subscribe to a specific frame in an animation, but with the latest version, 3.0.55 of this runtime library, you can provide a callback to useRive() via an onAdvance property, where the library will invoke your provided callback at the end of a given animation loop once Rive has drawn the current frame onto a canvas and pass back the elapsed time (in seconds) since the last frame draw.

Looks something like:

useRive({
  ...
  onAdvance: (time: number) => {
    console.log("time since last draw", time);
  }
})

zplata avatar Jul 19 '23 14:07 zplata