我一直致力于我的第一场比赛:)
这是一款基于Android的游戏,使用的是libgdx,正在使用DeWiTTERS loop
的修改示例游戏循环似乎在桌面上运行得非常好(59 - 60 fps)但是当我在手机上运行时,它往往会在75 - 90 FPS左右。
nextGameTick应该始终指向未来的16ms,以便游戏循环以60 FPS或更低的速度运行,为什么不是这种情况
以下是游戏循环的主要部分供参考:
public void render() {
nextGameTick = System.nanoTime() + skipTicks;
loopTimeFull = System.nanoTime();
Application app = Gdx.app;
screen.update(app); // Update the screen
screen.render(app); // Render the screen
// when the screen is done we change to the
// next screen
if (screen.isDone()) {
// dispose the current screen
screen.dispose();
<snip>
// Removed unneded part of code for this example
</snip>
}
}
// Make the thread sleep
General.renderTime = System.nanoTime() - loopTimeFull;
while (System.nanoTime() <= nextGameTick - General.renderTime) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
General.loopTime = System.nanoTime() - loopTimeFull;
if (General.loopTime > 0)
General.curFps = 1000000000 / General.loopTime;
else
Gdx.app.log("Air Offense", "General.loopTime == 0");