System.nanoTime()的问题

1 java

我正在进行2D游戏,但我仍然遇到计时器问题.这是我的游戏循环:

void gameLoop(isRunning){
....

doStuff();

....
}
Run Code Online (Sandbox Code Playgroud)

我在循环中有一个像这样的fps测量代码:

long thisLoop = System.currentTimeMillis();
delta = thisLoop - lastLoopTime;
lastLoopTime = thisLoop;
Run Code Online (Sandbox Code Playgroud)

所以我得到自上次循环以来已经过了多少时间.但是,每当我尝试使用System.nanoTime()而不是System,currentTimeMillis()像这样:

long thisLoop = System.nanoTime();
delta = thisLoop - lastLoopTime;
lastLoopTime = thisLoop;
Run Code Online (Sandbox Code Playgroud)

我的游戏完全搞砸了,没有渲染任何东西超过第一帧,没有错误报告只是冻结.我在胜利7 64最新java 1.6.可能有什么不对?

Whi*_*g34 5

尝试使用,System.nanoTime() / 1000000因为它是在纳秒内而不是毫秒,就像你可能期待的那样.