Hello.
I have a SimpleApplication, with the default blue cube. When I add this code to the simpleInitApp() method, it throws an exception:
// Remove default mappings
inputManager.deleteMapping(INPUT_MAPPING_CAMERA_POS);
inputManager.deleteMapping(INPUT_MAPPING_MEMORY);
This is the exception:ago 23, 2013 1:01:24 PM com.jme3.app.Application handleError SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.IllegalArgumentException: Cannot find mapping: SIMPLEAPP_CameraPos at com.jme3.input.InputManager.deleteMapping(InputManager.java:607) at mygame.UserInput.simpleInitApp(UserInput.java:65) at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225) at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207) at java.lang.Thread.run(Thread.java:722)
This is the full code of my simple application:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.input.controls.Trigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/**
-
test
-
@author normenhansen
*/
public class UserInput extends SimpleApplication {private Geometry geom;
private final static Trigger TRIGGER_COLOR = new KeyTrigger(KeyInput.KEY_SPACE);
private final static Trigger TRIGGER_COLOR2 = new KeyTrigger(KeyInput.KEY_C);
private final static Trigger TRIGGER_ROTATE = new MouseButtonTrigger(MouseInput.BUTTON_LEFT);private final static String MAPPING_COLOR = “Toggle Color”;
private final static String MAPPING_ROTATE = “Rotate”;private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) { System.out.println("You triggered action: " + name + ", isPressed?: " + (isPressed ? "Y" : "N") + ", tpf: " + tpf); if( name.equals(UserInput.MAPPING_COLOR) && !isPressed ){ geom.getMaterial().setColor("Color", ColorRGBA.randomColor()); } }
};
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) { System.out.println("You triggered analog: " + name + ", value: " + value + ", tpf: " + tpf); if( name.equals(UserInput.MAPPING_ROTATE) ){ geom.rotate(0, value, 0); } }
};
public static void main(String[] args) {
UserInput app = new UserInput();
app.start();
}@Override
public void simpleInitApp() {// Remove default mappings inputManager.deleteMapping(INPUT_MAPPING_CAMERA_POS); inputManager.deleteMapping(INPUT_MAPPING_MEMORY); inputManager.addMapping(MAPPING_COLOR, TRIGGER_COLOR, TRIGGER_COLOR2); inputManager.addMapping(MAPPING_ROTATE, TRIGGER_ROTATE); inputManager.addListener(actionListener, new String[]{MAPPING_COLOR}); inputManager.addListener(analogListener, new String[]{MAPPING_ROTATE}); Box b = new Box(Vector3f.ZERO, 1, 1, 1); this.geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); this.geom.setMaterial(mat); rootNode.attachChild(this.geom);
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}