Cursor Visibility & Catching

deepankdwivedi edited this page Dec 7, 2017 · 1 revision

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:

Gdx.input.setCursorPosition(x, y);

Note that catching the cursor only works reliably in the Lwjgl back-end. The Jogl backend uses the AWT/Swing Robot class which has a few quirks.

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

Cursor customCursor = Pixmap(Gdx.files.internal("cursor.png")), hotspotX, hotspotY);;

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:;

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


Prev | Next

Table of Contents

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.