[英]Slick2d - on close
I've recently started playing around with Slick2d in Java. 我最近开始在Java中使用Slick2d。 I need to catch an on close event, is there any simple way of doing this with slick2d?
我需要捕捉一个关闭事件,有没有简单的方法用slick2d做这个?
I have done this in my current project that is based on the BasicGame class, by overriding the closeRequested() method, something like this: 我在我当前的基于BasicGame类的项目中通过覆盖closeRequested()方法完成了这个,如下所示:
public class mySmallTestGame extends BasicGame{
.. other code ...
@Override
public boolean closeRequested()
{
System.exit(0); // Use this if you want to quit the app.
return false;
}
}
I don't think I've understood the question right, but assuming that you're waiting for he user to put in a keyboard stroke or two to end the program you could just put this in the update method. 我不认为我已经理解了这个问题,但假设你正在等待用户输入一两个键盘来结束程序,你可以把它放在更新方法中。
Input input = GameContainer.getInput();
if (input.isKeyPressed(Input.KEY_LALT) && input.isKeyDown(Input.KEY_F4)){
System.exit(0);
}
You could use the CanvasGameContainer class, which is a java.awt.Canvas. 您可以使用CanvasGameContainer类,它是一个java.awt.Canvas。 Adding that to a Frame and setting a WindowListener should do the trick.
将其添加到Frame并设置WindowListener应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.