Search code examples
javaslick2d

Slick: Quit game via button


What methods can I use to tell the game that the user has requested it to close with either the GameContainer or the StateBasedGame classes.

I have a button and upon it being clicked I want it to close the game, what is the function that needs to be run upon the listener finding out that close was requested?


Solution

  • The GameContainer class has an exit method:

    public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException
    {
      if(my_exit_flag)
        gc.exit();
    
      // Update code here
    }