Integrate a Mouse


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

        // 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,

// Make the mouse's background blend with what's already there
AlphaState as = display.getRenderer().createAlphaState();
        // 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
at Test1.update(
at Test1.main(
07.06.2009 23:26:42 start
INFO: Application ending.

What to do now?

well if 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!!!