Modifying the appearance of the cursor

I need to load the .cur .ani .ioc file into jme

InputManager (jMonkeyEngine3)

CursorLoader (jMonkeyEngine3)

AssetInfo (jMonkeyEngine3)

public class mouseCur extends BaseAppState{
    private InputManager inputManager;
    private AssetManager assetManager;
    private SimpleApplication simpleApp;
    private Camera cam;
    private CursorLoader cursorLoader;
    private AssetInfo assetInfo;
    private JmeCursor jmeCursor;
    @Override
    protected void initialize(Application aplctn) {
       simpleApp = (SimpleApplication) aplctn;
        assetManager = aplctn.getAssetManager();
        inputManager = aplctn.getInputManager();
        cam=aplctn.getCamera();
        
        //assetManager.loadAsset("Textures/ColdCyan/normal.cur");
         assetInfo = assetManager.locateAsset(new AssetKey<>("Textures/ColdCyan/normal.cur"));
        try {
            inputManager.setMouseCursor(cursorLoader.load(assetInfo));
        } catch (IOException ex) {
            Logger.getLogger(mouseCur.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    protected void cleanup(Application app) {
    }

    @Override
    protected void onEnable() {
   }

    @Override
    protected void onDisable() {
    }
    
}
严重: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException: Cannot invoke "com.jme3.cursors.plugins.CursorLoader.load(com.jme3.asset.AssetInfo)" because "this.cursorLoader" is null
	at RTSCamera.mouse.mouseCur.initialize(mouseCur.java:44)
	at com.jme3.app.state.BaseAppState.initialize(BaseAppState.java:129)
	at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:332)
	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:362)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:628)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:717)
	at java.base/java.lang.Thread.run(Thread.java:833)

YSBKX1Y3`%DG4B)3QX2O1I0
I don’t think there’s anything wrong with my file path.

I read the above link to understand how jme loads these files, and I’m pretty sure I’m missing something, but I don’t really know what I’m doing wrong right now.

public class mouseCur extends BaseAppState{
    private InputManager inputManager;
    private AssetManager assetManager;
    private SimpleApplication simpleApp;
    private Camera cam;
    private JmeCursor jmeCursor;
    @Override
    protected void initialize(Application aplctn) {
       simpleApp = (SimpleApplication) aplctn;
        assetManager = aplctn.getAssetManager();
        inputManager = aplctn.getInputManager();
        cam=aplctn.getCamera();
        jmeCursor = (JmeCursor) assetManager.loadAsset("Textures/ColdCyan/normal.cur");
       inputManager.setMouseCursor(jmeCursor);

    }

    @Override
    protected void cleanup(Application app) {
    }

    @Override
    protected void onEnable() {
   }

    @Override
    protected void onDisable() {
    }
    
}

I’ve changed the code a bit but there’s still something wrong with it.

严重: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.nio.BufferOverflowException
	at java.base/java.nio.IntBuffer.put(IntBuffer.java:1007)
	at com.jme3.cursors.plugins.CursorLoader$CursorImageData.<init>(CursorLoader.java:639)
	at com.jme3.cursors.plugins.CursorLoader.loadCursor(CursorLoader.java:228)
	at com.jme3.cursors.plugins.CursorLoader.load(CursorLoader.java:90)
	at com.jme3.cursors.plugins.CursorLoader.load(CursorLoader.java:56)
	at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:272)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:388)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:402)
	at RTSCamera.mouse.mouseCur.initialize(mouseCur.java:43)
	at com.jme3.app.state.BaseAppState.initialize(BaseAppState.java:129)
	at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:332)
	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:362)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:628)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:717)
	at java.base/java.lang.Thread.run(Thread.java:833)
    /**
     * Sets the cursor's image(s) data. Each image data should be consecutively
     * stored in the {@link IntBuffer} if more tha one image is contained in the
     * cursor.
     * @param imagesData the cursor's image(s) data. Each image data should be consecutively
     * stored in the {@link IntBuffer} if more than one image is contained in the
     * cursor.
     */
    public void setImagesData(IntBuffer imagesData) {
        this.imagesData = imagesData;
    }

I still don’t particularly understand this part, do I need to convert the PNG image to Intbuffer first ?

That seems like a good place to start

Seems there is a related topic

1 Like

This article has a lot of what I need that content, thanks a lot for the tips!

1 Like