Integrate a Mouse

Hi.



I'm new to jME and I've made the Flag Rush Tutorial more or less.

Now, I've got the problem that I don't manage to include a mouse in my app…

I can see something that looks like a cursor, but I can't move it…



I use this code which I found somewhere in the wiki:

        // Create a new mouse. Restrict its movements to the display screen.
        am = new AbsoluteMouse("The Mouse", display.getWidth(), display
                .getHeight());

        // Get a picture for my mouse.
        TextureState ts = display.getRenderer().createTextureState();
        URL cursorLoc = HelloMousePick.class.getClassLoader().getResource(
                "test2/cursor1.png" );
        Texture t = TextureManager.loadTexture(cursorLoc, Texture.MM_LINEAR,
                Texture.FM_LINEAR);
        ts.setTexture(t);
        am.setRenderState(ts);

// Make the mouse's background blend with what's already there
AlphaState as = display.getRenderer().createAlphaState();
as.setBlendEnabled(true);
as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
as.setTestEnabled(true);
as.setTestFunction(AlphaState.TF_GREATER);
am.setRenderState(as);
       
        // Get the mouse input device and assign it to the AbsoluteMouse
        // Move the mouse to the middle of the screen to start with
        am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display
                .getHeight() / 2, 0));

// Assign the mouse to an input handler
        am.registerWithInputHandler( input );


I think the problem is the last variable "input".
As this variable doesn't exist, I just created it myself, but I think I did something wrong...
InputHandler input;


Can anyone help me please?

InputHandler nedd to be updated in the update loop.



add a input.update() call in your simpleUpdate() method.

Thanks for your reply, but this doesn't work.

I work with a subclass of BaseGame, not SimpleGame…

And when i add input.update(), I need to put a float in the brackets, there i use the variable interpolation which is the time difference since the last update.

But I get an error when I use this:

SCHWERWIEGEND: Exception in game loop
java.lang.NullPointerException
at Test1.update(Test1.java:162)
at com.jme.app.BaseGame.start(BaseGame.java:79)
at Test1.main(Test1.java:100)
07.06.2009 23:26:42 com.jme.app.BaseGame start
INFO: Application ending.

What to do now?

well if Test1.java:162 is the line with your input.update(tpf) call, then the input is pointing to null.



You need to create the InputHandler in your constructor.

input = new InputHandler();

Now it works!

Thanks alot!!!