Deleting default input mappings failed

Hey there,

it’s me again for the second time :smile:

I bought the book “jMonkeyEngine 3.0 beginner’s guide” and the book said that I can delete the default input mappings by calling

inputManager.clearMappings();

I tried this an recognized, that the Escape key is not mapped anymore, but the other keybindings like W, A, S, D or C still work. What’s the reason? I also tried to delete only the mapping for the C-key by calling

inputManager.deleteMapping(INPUT_MANAGER_CAMERA_POS);

But the C key still works.

It’s because you’ve removed the mappings before the FlyByCamera has added them.

If you don’t want the fly camera then you can simple remove it or disable it. Get the FlyCamAppState from the state manager and remove it or disable it.

Thanks for that information.

I’m aware of the method to disable the fly cam, but I just wonder, if it is possible to clear the input mappings AFTER the FlyByCam has added them? Is there a possible place, maybe a method of SimpleApplication that I can overwrite, in order to clear the mappings?

I think it’s no good idea to do a “inputManager.clearMappings()” in the update method, since this is called periodically.

Well, you could add your own app state that just clears the mappings.

To me it seems way better to disable the stuff you don’t want instead of clearing all mappings completely. It may end up causing you issues later if you accidentally run it after you’ve added your own mappings and then wonder why your keys don’t work.

I had this misunderstanding at begining, but I just realized that I don’t need to clear all input mappings, I just need to remove or add as needed, as @pspeed stated.

For example, I have a function that toggle FlyByCam to a custom first person camera, so I just remove all bidings from FlyByCam and add my own binds:

    inputManager.removeListener(flyCam);
    inputManager.deleteMapping(FLYCAM_Left);
    inputManager.deleteMapping(FLYCAM_Right);
    inputManager.deleteMapping(FLYCAM_Up);
    inputManager.deleteMapping(FLYCAM_Down);
    inputManager.deleteMapping(FLYCAM_StrafeLeft);
    inputManager.deleteMapping(FLYCAM_StrafeRight);
    inputManager.deleteMapping(FLYCAM_Forward);
    inputManager.deleteMapping(FLYCAM_Backward);
    inputManager.deleteMapping(FLYCAM_Rise);
    inputManager.deleteMapping(FLYCAM_Lower);

    // both mouse and button - rotation of cam
    inputManager.addMapping(PLAYER_NODE_Left, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(PLAYER_NODE_Right, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(PLAYER_NODE_Up, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping(PLAYER_NODE_Down, new MouseAxisTrigger(MouseInput.AXIS_Y, true));

    // keyboard only WASD for movement and SPACE/LCONTROL for rise/lower height
    inputManager.addMapping(PLAYER_NODE_StrafeLeft, new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping(PLAYER_NODE_StrafeRight, new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping(PLAYER_NODE_Forward, new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping(PLAYER_NODE_Backward, new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping(PLAYER_NODE_Rise, new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping(PLAYER_NODE_Lower, new KeyTrigger(KeyInput.KEY_LCONTROL));

    inputManager.addListener(followCam, new String[]{
	PLAYER_NODE_Left,
	PLAYER_NODE_Right,
	PLAYER_NODE_Up,
	PLAYER_NODE_Down,
	PLAYER_NODE_StrafeLeft,
	PLAYER_NODE_StrafeRight,
	PLAYER_NODE_Forward,
	PLAYER_NODE_Backward,
	PLAYER_NODE_Rise,
	PLAYER_NODE_Lower
    });

You can find all FlyByCam binds on CameraInput source.

I had this problem a long time and I found a magical solution:

In your simpleInitApp():

stateManager.detach(stateManager.getState(DebugKeysAppState.class));;

It disbles the input from the C and M, but you can still quit with Esc and move the camera.

:slight_smile:

Another thing you can do is only include the app states you want in the first place. If you give your SimpleApplication subclass a constructor then it can pass super(just the app states you want).


public class MyApp extends SimpleApplication {
....
    public MyApp() {
        super(new FlyCamAppState(), 
                  new MyOwnAppState(), 
                  new MainMenuAppState(), 
                  new DayNightAppState(), ....);
    }
...

Here is the actual constructor from one of my games:

    public Main() {
        super(new StatsAppState(), new DebugKeysAppState(), new BasicProfilerState(false),
              new OptionPanelState(),
              new MainMenuState(),
              new StarFieldState(),
              new ScreenshotAppState("", System.currentTimeMillis())); 
    }