I've recently started playing around with Slick2d in Java. I need to catch an on close event, is there any simple way of doing this with slick2d?
I have done this in my current project that is based on the BasicGame class, by overriding the closeRequested() method, something like this:
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. Adding that to a Frame and setting a WindowListener should do the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.