在Java中调整游戏的FPS

时间:2014-06-12 00:23:40

标签: java android timing

我正在尝试规范我在Java中创建的游戏的fps。它应该每秒输出帧速率半秒。我在这里犯了什么错误。它在Android中,而不是Thread.sleep(time) I use handler.postDelayed(this, time)

if(!m.isPaused){
        long start = System.nanoTime();
        frames ++;
        cd.tick();
        long end = System.nanoTime();
        counter += ((waitMs - 2) * 1000000) - (end - start);
        if(counter >= 1000000000){
            System.out.println("Frames: " + frames + " counter: " + counter);
            counter = 0;
            frames = 0;
        }
        m.gameThread.postDelayed(this, waitMs - 2 - ((end - start) * 1000000));
        return;
    }
    m.gameThread.postDelayed(this, waitMs);

0 个答案:

没有答案