我正在编写一个游戏,我希望在进入游戏本身之前,有大约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秒后,游戏本身就会出现。我的代码出了什么问题?是不是有什么我现在不应该做的事情?
发布于 2013-09-29 00:08:38
绘制完整的JFrame需要4秒,因为您在代码中有4秒的休眠时间:
while (timer <= 4) {
try {
Thread.sleep(1000);发布于 2013-09-29 00:10:58
这个问题可能存在于Thread.sleep的while循环之后的图像变量中。
gfx.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null); 此图像使您的框架空白。
https://stackoverflow.com/questions/19068873
复制相似问题