-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onDraw
doesn't trigger
#186
Comments
Hi @smblee - I don't believe this is an exposed event you can subscribe to. Mind sharing where you found this property so we can fix up documentation? |
Found it in the typescript definition. I believe it's an existing Enum under Then are there any similar event i can subscribe to without opting to the |
@zplata any feedback above? |
Ahh I see what you mean - our Android and iOS runtimes have a concept of reporting back at the end of a render loop/frame after it has drawn onto the canvas/texture. We can provide an |
@zplata That would be very useful! |
Cool - will comment on this thread once that lands. Thanks for bringing this up! |
@zplata thanks! Do you know the ETA for this? I can also try to contribute if you can point me to the best place to hook into the render loop |
We should target having this change land downstream on rive-wasm this week - from there, it should be a quick update to React |
@zplata while at this, is it possible to also add a hook to draw different elements during the canvas draw cycle? (Without having to ditch the whole React library and use the raw canvas lib) I am imagining adding some hooks to like (super trivial example) function mainAnimationCallback(time) {
// Snap off and reset the sub-callbacks first, since they might call requestAnimationFrame
// recursively.
const flushingSubCallbacks = _animationSubCallbacks;
_mainAnimationCallbackID = 0;
_lastAnimationSubCallbackID = 0;
_animationSubCallbacks = new Map();
// Invoke all pending animation callbacks.
flushingSubCallbacks.forEach((callback) => {
try {
callback(time);
} catch (err) {
console.error(err);
}
});
+ this.onFrameDraw(context); // pass anything else that could be useful
this.onAfterCallbacks();
if (_fpsCounter) {
_fpsCounter.frameComplete();
}
} And consume it like rive.onFrameDraw((ctx) => {
// draw other dynamic stuff outside of rive
ctx.beginPath();
...
if (... game logic ...) { ... }
}) Would love to leverage the existing React niceties like screen resize, fit, start/reset functions, and etc. My use case here is drawing the mouse cursor location every frame to customize the look of the mouse within the canvas, and also check for collision detection. |
…occurred Adding a hook to report back the end of a render loop (as requested [here](rive-app/rive-react#186)). This will add consistency with iOS and Android callbacks too. Diffs= 2de1f249c feature: Add onAdvance hook into render loop to report advancing has occurred (#5520) Co-authored-by: Zachary Plata <[email protected]>
Hi! Sorry for the delay - just as an update, we've landed the Regarding your other comment, there isn't a straightforward way to hook into when individual elements draw. The |
@zplata Thanks for getting around to this. i think the problem with pointer based events (whether within rive or within the code) is the events don't trigger until the mouse actually "moves". E.g. https://rive.app/community/3571-7464-tunnel-dodger/ if you don't move your cursor at all, the collision detection actually won't get triggered even upon collision. This is why I need to run the collision detection upon every frame render using a separate state to track the cursor position. With the |
@zplata small nudge on the progress 👀 |
Oh sorry, I totally dropped the ball on updating this thread - should be in |
@zplata amazing! Thank you. Could you also comment on my comment above? What are your thoughts on best way to resolving that collision detection? Maybe the new |
I noticed one of the EventType is
Draw
but can't seem to get any callbacks.^ this is the code i am running. I can't really find much documentation around this either.
Does this properly not exist?
The text was updated successfully, but these errors were encountered: