I'm using BasicGameState for Standard game, and I wanna know how can I retrieve my Inputs, so I can do, for i.e:
input.addAction(accelAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_U, InputHandler.AXIS_NONE, false);
Thank you :D
I'm using BasicGameState for Standard game, and I wanna know how can I retrieve my Inputs, so I can do, for i.e:
input.addAction(accelAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_U, InputHandler.AXIS_NONE, false);
There are many ways.
You could use Gamecontrols / GamecontrolManager.
take a look at http://code.google.com/p/jmonkeyengine/source/browse/trunk/src/jmetest/input/controls/TestControls.java
So, Core-Dump, I have a question about TestControls.java. I can see in the code the part that sets up the Controls, but not the part that says what to do when use that command. Can you it show me?
The GameControl system is quite flexible and easy to work with and extend.
The ThrottleController and RotationController are predefined Controllers, you pass the GameControls you defined, and the controller rotates your object.
In the example also a ActionChangeController is used, where you just implement the changed() Method.
ActionChangeController quit = new ActionChangeController(exit, new ControlChangeListener() {
public void changed(GameControl control, float oldValue, float newValue, float time) {
if (newValue == 1.0f) {
game.shutdown();
}
}
});
// Lock target
manager.addControl("lockTarget").addBinding(new KeyboardBinding(KeyInput.KEY_L));
ActionController lockTargetController = new ActionController (manager.getControl("lockTarget"), new GameControlAction() {
public void pressed(GameControl control, float time) {
targetDevice.toggleLock();
}
public void released(GameControl control, float time) {
}
});
node.addController(lockTargetController);
I tried to do what you said, so at my BasicGameState init method, I call the method 'configureControls()':
public void configureControls() {
GameControlManager manager = new GameControlManager();
GameControl forward = manager.addControl("forward");
forward.addBinding(new KeyboardBinding(KeyInput.KEY_W));
ActionController forwardController = new ActionController (manager.getControl("Forward"), new GameControlAction() {
public void pressed(GameControl control, float time) {
pivotNode.getWorldRotation().mult(lookingDirection, lookingDirection);
walkDirection.addLocal(lookingDirection);
character.setWalkDirection(walkDirection);
}
public void released(GameControl control, float time) {
}
});
pivotNode.addController(forwardController);
}
Exception in thread "main" java.lang.NullPointerException
at jme.game.SimpleGameState.configureControls(SimpleGameState.java:107)
at jme.game.SimpleGameState.init(SimpleGameState.java:84)
at jme.game.SimpleGameState.<init>(SimpleGameState.java:60)
at jme.game.Main.main(Main.java:16)
addControl("forward");
getControl("Forward"),
you could use enum's or constants to avoid such typos