How can I change the mouse a cursor to a picture using libGDX?



Pixmap pm = new Pixmap(Gdx.files.internal("cursorImage.png"));
Gdx.graphics.setCursor(Gdx.graphics.newCursor(pm, 0, 0));

Before v1.7.0

Pixmap pm = new Pixmap(Gdx.files.internal("cursorImage.png"));
Gdx.input.setCursorImage(pm, 0, 0);

The hotspot parameters represent the "tip" of the cursor. For example, the operating system cursor has the hotspot at the top-left corner, but a crosshair cursor might have the hotspot at its center.

  • \$\begingroup\$ Thank you! Well but I have a problem the method Gdx.input.setCursorImage(image, xPos, y Pos); give this error The method setCursorImage(Pixmap, int, int) is undefined for the type Input \$\endgroup\$ Oct 28 '14 at 10:37
  • \$\begingroup\$ Well the function certainly exists, but it was added a year ago this month, so make sure you're using the latest version of libgdx. If you are and you're still getting that error, then I don't think I can help. \$\endgroup\$ Oct 28 '14 at 17:57
  • 2
    \$\begingroup\$ Gdx.graphics.setCursor(Gdx.graphics.newCursor(pm,0,0,)); \$\endgroup\$ Jan 11 '16 at 22:07
  • \$\begingroup\$ Is it worth keeping the pixmap in case I change often ? \$\endgroup\$
    – Winter
    Jan 4 '17 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.