对话框和FPS更改

时间:2014-01-08 06:50:07

标签: java android multithreading dialog frame-rate

这是一个非常广泛的问题,但有没有人知道为什么对话框似乎会影响Android上的帧率?例如,当我在游戏运行时显示和关闭对话框时,移动变得缓慢且不连贯。但是,游戏内爆炸的帧率提高了。我已经尝试了所有我能想到的东西,似乎没有任何帮助。任何帮助非常赞赏。

我如何显示对话框:

private void showPauseMenu() {
    isRunning = false; //tells the game thread that the game is no longer running
    paused = true; //tells the game thread that the game is paused
    ourThread = null; // nulls the Thread object until the game is resumed
    pause.show();
}

我如何摆脱对话并再次开始游戏:

isRunning = true;
ourThread = new Thread(this);
if (paused) {
    paused = false;
    pause.dismiss();
}
ourThread.start();

FPS计算

    if (elapsedTime < 33) {
        timeToSleep = 33 - elapsedTime;
    } else {
        timeToSleep = 0;
        Log.i("fps", "sleeping over 33ms");
    }
    try {
        Thread.sleep(timeToSleep);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Log.i("fps", "" + 1000 / (elapsedTime + timeToSleep));

1 个答案:

答案 0 :(得分:1)

该对话框也在UI线程中运行。 UI线程中运行的工作负载越多,导致FPS越低。即使您在游戏线程中运行游戏逻辑,所有图形工作仍然在UI线程中运行。这就是对话框会影响你的FPS的原因。