I was thinking that for some projects I do 60fps is not totally needed. I figured I could have more objects and things that ran at 30fps if I could get it to run smoothly at
The accepted answer has a problem and gives up to -10fps on slow computers compared to not limiting the fps, so for example without limiting 36pfs, with the accepted solution 26fps (for a 60fps, 1000/60 setTimeout).
Instead you can do this:
var dt=1000/60;
var timeTarget=0;
function render(){
if(Date.now()>=timeTarget){
gameLogic();
renderer.render();
timeTarget+=dt;
if(Date.now()>=timeTarget){
timeTarget=Date.now();
}
}
requestAnimationFrame(render);
}
That way is not going to wait if its already behind.