我一直在制作我的第一款游戏:)
这是一个使用 libgdx 的基于 android 的游戏,并且使用了DeWiTTERS 循环的一个修改示例
游戏循环似乎在桌面上运行得非常好(59 - 60 fps),但是当我在手机上运行时,它往往会在 75 - 90 FPS 左右
nextGameTick 应该总是指未来 16 毫秒,以便游戏循环以 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");