1

我正在学习 HTML 5 游戏编程。我遇到一个代码

var pingpong = {};
pingpong.pressedKeys = [];

$(function(){

    pingpong.timer = setInterval(gameloop,30);

    function gameloop() {
        movePaddles();

    } //end of gameloop()

}); //end of $(fn)

然后作者说

We have a timer to execute some game-related code every 30 milliseconds, so this 
code is executed 33.3 times per second.

我想问一下,每秒33.3次是怎么回事?我们如何计算它?

谢谢

4

2 回答 2

1

1 秒1000 毫秒

因此,如果代码每30 毫秒运行一次,则代码每秒执行 1000/30 = 33.3次。

于 2012-08-16T10:37:36.863 回答
0

一秒是 1000 毫秒,并setInterval(gameloop, 30)确保代码每 30 毫秒运行一次,因此,1000 / 30 = 33.3.

于 2012-08-16T10:38:14.850 回答