1

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?

njallam
  • 476
  • 9
  • 23
  • I apologise for the stupid question. I was unsure if I needed to run any shutdown scripts at the time. I will implement so that it is saved upon entering the QuitGameState. – njallam Aug 04 '12 at 08:28

2 Answers2

3

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
}
jjga
  • 46
  • 3
0

You can close any java application using

System.exit();

or

System.exit(<error_level>);
Dheeraj Bhaskar
  • 18,633
  • 9
  • 63
  • 66