Loop forever and provide delta time

前端 未结 4 757
别跟我提以往
别跟我提以往 2021-01-03 07:01

I\'m writing an HTML5 Game Development Javascript framework and I want to provide the user the difference in time between the last tick and the current one.

         


        
4条回答
  •  旧时难觅i
    2021-01-03 07:20

    Are you over thinking it?

    var myInterval = window.setInterval(calculateForDeltaHere , 20);
    
    function calculateForDeltaHere () {
        /* Calculate delta time */
        dt = Math.random();
        tick(dt);
    }
    
    function tick() {  
      update();
      draw();
    }
    

    And when you want to stop the interval

    window.clearInterval(myInterval);
    

提交回复
热议问题