我尝试使用Thread.sleep(),但是在非常短暂地显示游戏之前,它会完全暂停程序。我也尝试过在Thread.sleep()之前通过文本显示游戏,但我看不到它。以下是我目前正在使用的内容。
try{
Thread.sleep(2000);//pause for 2 seconds
//display gameover
gr.setColor(Color.WHITE);
gr.setFont(new Font("arial", Font.BOLD, 50));
gr.drawString("Game Over", 550, 300);
}
catch(InterruptedException e){
}
showText
例如,您可以定义一个布尔值,然后使用它来确定是否要显示文本。
public void runGameLogic() {
showText = true;
Timer t = new Timer(2000, (action) -> {
showText = false;
});
t.setRepeats(false);
t.start();
}
public void render() {
if (showText) {
gr.setColor(Color.WHITE);
gr.setFont(new Font("Arial", Font.BOLD, 50));
gr.drawString("Game Over", 550, 300);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句