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


1 Answer 1



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, 2014 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, 2014 at 17:57
  • 2
    \$\begingroup\$ Gdx.graphics.setCursor(Gdx.graphics.newCursor(pm,0,0,)); \$\endgroup\$ Jan 11, 2016 at 22:07
  • \$\begingroup\$ Is it worth keeping the pixmap in case I change often ? \$\endgroup\$
    – Winter
    Jan 4, 2017 at 18:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .