【发布时间】:2014-01-18 12:44:10
【问题描述】:
我正在使用 libgdx 为 android 开发一个小游戏,并希望将 fps 限制为 30 以节省电池。问题是它不起作用。 fps 刚刚从 60 下降到 56。
这是代码的一部分:(它在渲染部分的末尾)
System.out.print("\nFPS: " + Gdx.graphics.getFramesPerSecond() + "\n");
if(Gdx.graphics.getDeltaTime() < 1f/30f)
{
System.out.print("DeltaTime: " + Gdx.graphics.getDeltaTime() + " s\n");
float sleep = (1f/30f-Gdx.graphics.getDeltaTime())*1000;
System.out.print("sleep: " + sleep + " ms\n");
try
{
Thread.sleep((long) sleep);
}
catch (InterruptedException e)
{
System.out.print("Error...");
e.printStackTrace();
}
}
这是输出:
FPS: 56
DeltaTime: 0.014401722 s
sleep: 18.931612 ms
FPS: 56
DeltaTime: 0.023999143 s
sleep: 9.334191 ms
FPS: 56
DeltaTime: 0.010117603 s
sleep: 23.215733 ms
提前谢谢...
【问题讨论】:
标签: java android libgdx limit frame-rate