AppStates Disable State

Hi,



Newbie with jMonkey, I am teaching tutorials to better understand your “seems to be” awesome engine :wink:



I am currently teaching AppState thanks to the common tutorial. My remark is about the proposed update() method :



[java] @Override

public void update(float tpf) {

if(isEnabled()){

// do the following while game is RUNNING

System.out.println(“Enabled”);

} else {

// do the following while game is PAUSED, e.g. play an idle animation.

System.out.println(“Disabled”);

}

}[/java]



When this appstate is enable, at each frame, I have a new “Enabled” in the console. But I never see “Disabled



To understand why I look at AppStateManager source code and particulary at the update method :



[java] for (AppState state : array){

if (state.isEnabled()) {

state.update(tpf);

}

}[/java]



The condition on the enable state of each appstate prevent from running them if they are disable, seems to be ok.



Is the tutorial outdated ?



Thanks.



Pierre

It does look rather like it might be…

If the AppState is disable, the else part of code is never launch :



[java]

if(isEnabled()){

// do the following while game is RUNNING



} else {

// do the following while game is PAUSED, e.g. play an idle animation.



}[/java]

This is correct… disabled app states are not called. The tutorial must be ancient because update() has never been called on a disabled app state for as long as I’ve been using them.

I modified the tutorial.

1 Like

So the better way to display some “pause” stuff is to put the code in the @Overrided setEnabled(boolean b) method ?

@psidoler said:
So the better way to display some "pause" stuff is to put the code in the @Overrided setEnabled(boolean b) method ?


Or add a separate PausedAppState and disable the main one. Remove the paused app state when you are ready to resume and re-enable the main game app state.

Personally, I consider the "disabled" state of an AppState to mean that it's no longer doing anything and has cleaned the relevant stuff from the scene. So, for example, a HudState would completely hide or remove its stuff if disabled. A main game state might be different and I don't know how you are actually pausing it, ie: keeping the regular keys from working, etc..