Change the cursor image

Hey All

I want to change the image of my cursor but it’s harder then I thought. What I did nog was adding a picture to the guiNode and when I move my mouse the cursor moves with it (but with some relay). Because of this relay it’s actually impossible to use this methode. The mouse doesn’t move as smooth as a normal mouse.

In jme2 it is possible to change it, but in jme3 it looks like a pain in the ass. Is it possible with niftygui? Or another solution?

Thanks in advance

This is my mousecursor class.



[java]package ui.gui.gui3D;



import com.jme3.asset.AssetManager;

import com.jme3.math.Vector2f;

import com.jme3.ui.Picture;



public class MouseCursor extends Picture {



private AssetManager assetManager;



public MouseCursor(AssetManager assetManager) {

super("Mouse");



this.assetManager = assetManager;





super.setWidth(32);

super.setHeight(32);



this.setNormal();

}



public void setPosition(Vector2f position) {

super.setPosition(position.x, position.y-31);

}



public void setNormal() {

super.setImage(assetManager, "Interface/cursor.png", true);

}



public void setAttack() {

super.setImage(assetManager, "Interface/attackCursor.png", true);

}

}

[/java]



So in my SimpleApplication I do the following

[java]private void initKeys() {

inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));

inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));

inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_UP));

inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_DOWN));



inputManager.addMapping("Attack", new MouseButtonTrigger(0));



inputManager.addMapping("Move",

new MouseAxisTrigger(MouseInput.AXIS_X, true),

new MouseAxisTrigger(MouseInput.AXIS_Y, true),

new MouseAxisTrigger(MouseInput.AXIS_X, false),

new MouseAxisTrigger(MouseInput.AXIS_Y, false));



inputManager.addListener(this, new String[]{"Left", "Right", "Up", "Down", "Attack", "Move"});

}



@Override

public void onAnalog(String name, float value, float tpf) {

if(name.equals("Move")) {

cursor.setPosition(inputManager.getCursorPosition());

}

}[/java]



What am I doing wrong?

I just tested it and there was no delay at all. The fake mouse is just as smooth as the real mouse.

Maybe you’re not using the right method of changing it?

I commited a test called TestSoftwareMouse that shows how to do it properly.

Unless I enable vsync, I cannot notice the difference between software and hardware mouse

1 Like