State Not Changing

@t0neg0d said: Okay, so this section of code from Main.java

[java]
public void onAction(String binding, boolean isPressed, float tpf) {
System.out.println(“Test 1”);
if (binding.equals(“Next”)) {
System.out.println(“Test 2”);
if (isPressed) {
System.out.println(“Test 3”);
stateManager.detach(mainMenu);
stateManager.attach(game);
}
}
}
[/java]

if you add the above println’s… which actually print?
Next question is, is this mapping being removed once you load game? If not, it would just try and remove a state that doesn’t exist and then reinitialize the game.
You may want to move these specific bindings to the AppState they apply too, so in initialize of MainMenu these bindings would be added and on cleanup of MainMenu they would be removed. That way you don’t have code lingering around that applies to a specific AppState unintentionally

It works the other way around though. It is working, but just not when it goes to the Game State.

@akshaypathak1011 said: It works the other way around though. It is working, but just not when it goes to the Game State.

Of course it wouldn’t… the code detaches the mainMenu instance and attaches the game instance… no matter what state is already attached.

You could:

[java]
public void onAction(String binding, boolean isPressed, float tpf) {
if (binding.equals(“Next”)) {
if (isPressed) {
if (stateManager.getState(MainMenu.class) != null) {
stateManager.detach(mainMenu);
stateManager.attach(game);
} else {
stateManager.detach(game);
stateManager.attach(mainMenu);
}
}
}
}
[/java]

But as it is right now, nothing would change after loading the game state.