开发者

Slick2d - on close

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;
    }

}


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.


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);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜