Is this the best way to render the sprite & camera position each second? #1455
Unanswered
nazrinnoorzan
asked this question in
Q&A
Replies: 1 comment 3 replies
-
i see no problem unless the positions are fast updates, in that case it would tank performance. one thing that is weird is ThreeCamera. you give it the data as a prop, but useFrame executes every frame (60 frames per second). if it just gets a prop and you want to set the camera that should be a useLayoutEffect. but if you went for useFrame because these prop updates happen very fast, then that points to a real issue and optimally ThreeCamera shouldn't get that state through props but transiently inside useFrame without causing render. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've a React project that receives a position, color & camera data from an API. These three data are been stored in main App.js states and I pass these states as a prop to R3F Canvas component.
So far, I can see it is working well. The sprites position keep moving, so does the camera. My concern is, is this the right way to render the sprite animations? Will Canvas keep re-render by passing the App.js states to it?
Here's my codes for App.js, ThreeCanvas.js & ThreeCamera.js (All are in separate files)
App.js
ThreeCanvas.js
ThreeCamera .js
Beta Was this translation helpful? Give feedback.
All reactions