gpt4 book ai didi

java - 私有(private) Void Tick();不工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:20 26 4
gpt4 key购买 nike

该功能无法正常工作,不知道如何解决此问题。如果有帮助我正在使用这个tutorial .

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.createBufferStrtegy(3);
return;
}

Graphics g = bs.getDrawGraphics();



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

}

最佳答案

将 tick() 和 render() 方法移出 run() 方法,并从方法声明中删除分号。

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.createBufferStrtegy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.dispose();
bs.show();
}

关于java - 私有(private) Void Tick();不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31760188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com