I’ve added to my main app mapping for ESC (escape) key with listener directing it to main menu, but for some reason, game still exits after pressing ESC, even though I have listener that should block it.
I want my game to go to main menu upon pressing ESC, not quit.
My code:
[java]
//In simpleInitApp
inputManager.addMapping(“profiler”, new KeyTrigger(KeyInput.KEY_F3));
inputManager.addMapping(“FPS”, new KeyTrigger(KeyInput.KEY_F4));
inputManager.addMapping(“MainMenu”, new KeyTrigger(KeyInput.KEY_ESCAPE));
inputManager.addListener(Global, “profiler”,“FPS”,“MainMenu”);
//
//Listener "Global":
ActionListener Global = new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("profiler") && !isPressed) {
profiler = !profiler;
UpdateSettings(); // update settings is function that updates visibility
//of fps counter and profiler at same time, so I don't have to have same code in different places
} else if (name.equals("FPS") && !isPressed) {
fpsCounter = !fpsCounter;
UpdateSettings();
} else if (name.equals("profiler") && !isPressed) {
profiler = !profiler;
UpdateSettings();
}
}
};[/java]