I have a piece of software that I wrote which fires repaints of the screen as soon as the updating logic is finished. The issue is that the updating logic happens over 1000 times per second. The browser cannot update the screen this quickly, so I figured that a requestAnimationFrame would allow me to update the screen for the user in a slower manner.
I structured the code like so:
function repaint(){
now = Date.now();
elapsed = now-then;
if(elapsed > 2000){
.
.
.
//animation goes here
.
.
.
then = Date.now();
}
}
function startRepaint(){
then = Date.now();
requestAnimationFrame(repaint);
}
while(count < 1000){
.
.
.
startRepaint();
.
.
.
}
Can I use requestAnimationFrame in this way to achieve my desired functionality?