For some games like first person shooters, it is often necessary to catch the cursor so it stays in the center of the screen, and only use position deltas to rotate the camera. Other times we might want to position the cursor manually. Both things can be done as follows:

    1. Gdx.input.setCursorCatched(true);
    2. Gdx.input.setCursorPosition(x, y);

    Note that catching the cursor only works reliably in the LWJGL/LWJGL3 back-ends.

    Cursor catching and positioning is only available on the desktop.

    Similarly, changing the cursor image is available on the desktop and on gwt if the browser supports the “cursor:url()” syntax and also supports the png format as cursor. It can be done as follows:

    Note: You Should dispose the cursor if you don’t need it anymore

    1. Cursor customCursor = Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("cursor.png")), hotspotX, hotspotY);
    2. Gdx.graphics.setCursor(customCursor);

    You can also change the cursor to a system cursor, this only works in the LWJGL3 backend and in the GWT backend. It can be done as follows:

    1. Gdx.graphics.setSystemCursor(SystemCursor.Crosshair);

    Supported system cursors are the

    • Arrow Image of an arrow cursor
    • Ibeam Image of an i-beam cursor
    • Crosshair Image of a crosshair cursor
    • Hand Image of a pointer cursor
    • HorizontalResize Image of a horizontal-resize cursor
    • VerticalResize Image of a vertical-resize cursor

    cursors.

    Prev | Next