我正在编写一个游戏,我希望在进入游戏之前有大约 3-5 秒的公司徽标。这是我的代码:
Graphics gfx = buffer.getDrawGraphics();
gfx.setColor(new Color(146, 17, 189));
gfx.fillRect(0, 0, this.getWidth(), this.getHeight());
// Draw stuffs between here...
gfx.drawImage(icon.getImage(), 0, 0, this.getWidth(), this.getHeight(), null);
int timer = 0;
while (timer <= 4) {
try {
Thread.sleep(1000);
} catch (InterruptedException exc) {
exc.printStackTrace();
System.out.println("Could not put thread to sleep! :(");
}
timer++;
}
gfx.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
if (key.showFPS == true) {
//Set it up so that it still works with the "per second" rule.
key.showPerSeconds(buffer, FPS, TPS);
}
// and here.
gfx.dispose();
buffer.show();
}
我的主要问题是出现了一个空白的 JFrame,然后 4 秒后,游戏本身出现了。我的代码有什么问题?有没有我现在不应该做的事情?