rive-app / rive-react

React runtime for Rive

Home Page:https://rive-app.github.io/rive-react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get current frameTime or frameCount

smblee opened this issue · 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)

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);
  }
})