Java游戏循环未更新

时间:2018-12-22 07:27:32

标签: java while-loop

我正在关注本教程:https://youtu.be/1gir2R7G9ws?t=891(是的,但谁在乎)在14:51。您可以在18:09看到循环正在工作,因为他可以更改颜色并查看fps。但是,即使更改颜色,窗口也无法显示在16:06可见的颜色。

我曾经尝试更改缓冲区,但是我是java的新手,所以我不知道如何解决,因为没有错误。

public void run() {
    long lastTime = System.nanoTime();
    double amountOfTicks = 60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    long timer = System.currentTimeMillis();
    int frames = 0;
    while (running) {
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;
        while (delta >= 1) {
            tick();
            delta--;
        }
        if (running)
            render();
        frames++;

        if (System.currentTimeMillis() - timer > 1000) {
            timer += 1000;
            System.out.println("FPS: " + frames);
            frames = 0;
        }
    }
    stop();
}

private void tick() {

}

private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
        this.createBufferStrategy(3);
        return;
    }

    Graphics g = bs.getDrawGraphics();

    g.setColor(Color.green);
    g.fillRect(0, 0, WIDTH, HEIGHT);

    g.dispose();
    bs.show();
}

我正在树莓派(3 b +)树莓派上运行它,这可能是问题吗?

0 个答案:

没有答案