Javascript - Can't Adjust FrameRate - requestanimationframe

前端 未结 7 2049
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 03:50

I start the loop

function gameLoop(){
   update();
   draw();
   requestAnimFrame(gameLoop);
}

var requestAnimFrame =  window.requestAnimationFrame ||
                  


        
7条回答
  •  伪装坚强ぢ
    2021-02-06 04:29

    You should look at this article which gives a proper treatment of the subject. http://creativejs.com/resources/requestanimationframe/

    var fps = 15;
    function draw() {
        setTimeout(function() {
            requestAnimFrame(draw);
            // Drawing code goes here
        }, 1000 / fps);
    }
    

    Here is the code I think you want, but in the original article it said used requestAnimationFrame, but here I am using requestAnimFrame. I think maybe it changed and you're supposed to use requestAnimFrame now. requestAnimationFrame did not work for me while requestAnimFrame did.

提交回复
热议问题