GameState shutdown

Been using the GameState API and was wondering how the best way to do a clean shutdown was.

In this scenario;

I’ve two states, Menu and InGame. When InGame, pressing ESC brings up a menu. When pressing ESC again from the MenuState, I’d like to terminate the program, but can’t see a clean way of leaving the current state but not switching to another one.

I’m probably doing it all wrong with this approach, but you have to start somewhere.


Yes, this is sort of a problem :slight_smile:

I’m using this solution:

public class MyGame extends BaseGame {
    // Only used in the static exit method.
    private static MyGame instance;

    public void initGame() {
        instance = this;

    * Static method to exit to OS.
    public static void exit() {

Then just call MyGame.exit() as you press ESC in your main menu.

Hope that helps.

Thanks for your reply. I kind of went off down the JavaBeany way of doing it with a registered exitNotifier interface and such.

‘Many ways to skin a cat’ as they say.