I was wondering what is the best way to implement a visualization tool in JavaScript. This is not the substantial part of the rendering, which is really important here - I would like to hear when and how to effectively run the visualization code.
I currently have window.setInterval(renderFunc, 1000 / 20)one that will just display a frame every 50 ms (i.e. fps = 20).
The fact is that faster computers will not display more frames, and slower computers will not be able to catch up to 20 frames per second, so the function is called more than the computer can handle.
I thought about the loop while(true), but it uses a 100% processor and slows down the computer itself - so my game (rendering from my 3D game) will no longer play, because you can no longer press the buttons.
What is the most effective option in this scenario, or is there a better method that has not crossed my mind?
Thanks in advance.
source
share