what i've done is to tweak the StateBasedGame class, i've also added some "hooks" for a resume and exit,
(the D is my enumeration class), so if you pause, you keep the last state id in memory and you do a transition to your paused state
if you resume you get the last state back by id and everyting "resumes" automatically without doing noting, the state is paused (not rendered or updated)
until you go back to that state
(if you want i can post you the complete class)
but i changed it quite a lot to my needs because my states are "dynamic"..
cheers
-a-
Code:
public StateBasedGame(String name) {
this.title = name;
currentState = new BasicGameState() {
public D getID() {
return D.NULL;
}
public void init(GameContainer container, StateBasedGame game) throws SlickException {
}
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
}
public void resume() throws SlickException {
}
public void pause() throws SlickException {
}
public void exit(GameContainer gc, StateBasedGame sbg) {
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
}
};
}
....
/**
* Pause a particular game state with the transitions provided
*
* @param pauseId the id of the state to pause
* @param id The ID of the state to enter
* @param leave The transition to use when leaving the current state
* @param enter The transition to use when entering the new state
*/
public void pauseState(D pauseId, D id, Transition leave, Transition enter) {
this.pauseId = pauseId;
enterState(id, leave, enter);
}
public void resumeState(Transition leave, Transition enter) {
enterState(this.pauseId, leave, enter);
}