ESCAPE Key

Hello,

To improve user experience, i wanted to redirect the escape key to a user friendly window asking to confirm (among other stufs like save game/load…)

but i can’t do this

    inputManager.removeListener(actionListener);            

cos actionlistener defined ins SimpleApplication is protected

so i tried to copy the SimpleApplication to a custom one, but there are many fields that are also protected so it is unfeasible

how could i achieve this ?

thx

The default mappings in SimpleApplication is

[java]
if (inputManager.hasMapping(INPUT_MAPPING_EXIT)) {
inputManager.deleteMapping(INPUT_MAPPING_EXIT);
}
if (inputManager.hasMapping(INPUT_MAPPING_CAMERA_POS)) {
inputManager.deleteMapping(INPUT_MAPPING_CAMERA_POS);
}
if (inputManager.hasMapping(INPUT_MAPPING_MEMORY)) {
inputManager.deleteMapping(INPUT_MAPPING_MEMORY);
}
if (inputManager.hasMapping(INPUT_MAPPING_HIDE_STATS)) {
inputManager.deleteMapping(INPUT_MAPPING_HIDE_STATS);
}
[/java]

1 Like
@perfecticus said: The default mappings in SimpleApplication is

[java]
if (inputManager.hasMapping(INPUT_MAPPING_EXIT)) {
inputManager.deleteMapping(INPUT_MAPPING_EXIT);
}
if (inputManager.hasMapping(INPUT_MAPPING_CAMERA_POS)) {
inputManager.deleteMapping(INPUT_MAPPING_CAMERA_POS);
}
if (inputManager.hasMapping(INPUT_MAPPING_MEMORY)) {
inputManager.deleteMapping(INPUT_MAPPING_MEMORY);
}
if (inputManager.hasMapping(INPUT_MAPPING_HIDE_STATS)) {
inputManager.deleteMapping(INPUT_MAPPING_HIDE_STATS);
}
[/java]

And for the record, these two:
INPUT_MAPPING_CAMERA_POS
INPUT_MAPPING_MEMORY

Are setup by the DebugKeysAppState and so will a) happen after simpleInitApp(), and b) can be more easily removed by just removing the app state (or just not including it).

1 Like
<cite>@pspeed said:</cite> And for the record, these two: INPUT_MAPPING_CAMERA_POS INPUT_MAPPING_MEMORY

Are setup by the DebugKeysAppState and so will a) happen after simpleInitApp(), and b) can be more easily removed by just removing the app state (or just not including it).

so just adding these lines to simpleinitapp will do the trick ?

how do i remove the DebugKeyAppState ?

also, is it possible to catch when the user presses the X to close the window, in case of windowed utilisation ?

Removing an app state based on class:
stateManager.detach( stateManager.getState( SomeClass.class ) );

So replace the word “SomeClass” with “DebugKeysAppState” and you will no longer have the debug keys setup.

Though if you don’t want it in the first place it is often easier to instantiate SimpleApplication with just the states you want.

So something like:

[java]
public class MyGame extends SimpleApplication {
public MyGame() {
super( new MyAppState(), new MyOtherAppState(), new FlyCamAppState(), new StatsAppState() );
}
}
[/java]

In fact, in a well architected game, simpleInitApp and simpleUpdate are empty or close to empty.

1 Like
@curtisnewton said: also, is it possible to catch when the user presses the X to close the window, in case of windowed utilisation ?

Supposedly, override:
http://hub.jmonkeyengine.org/javadoc/com/jme3/app/Application.html#requestClose(boolean)

I have not tested this recently.

<cite>@pspeed said:</cite> Supposedly, override: http://hub.jmonkeyengine.org/javadoc/com/jme3/app/Application.html#requestClose(boolean)

I have not tested this recently.

yes !! it works
thx man :wink: