I'm able to create a custom cursor no problem using the following code running in my GameScreen's Show method:

Pixmap pixmap = new Pixmap(Gdx.files.internal("ui/cursor.png"));
Cursor cursor = Gdx.graphics.newCursor(pixmap, pixmap.getWidth() / 2, pixmap.getHeight() / 2);

The problem is...if I deselect the game window and return back...the cursor has returned back to the default one. At least that happens for me on Mac desktop. If I move the cursor out of the screen (without deselecting) and then back again I get the custom cursor image back but I don't think people would know to do that.

But after searching I couldn't find any way for LibGDX to detect when the game window is deselected? I thought I would be able to find that since it would seem useful for something like automatically pausing when deselecting the game window and such.

That would seem to be the way to reset the cursor every time returning to the game window, unless there's some other way to make it more permanent?

EDIT: The cursor in fact just seems to randomly disappear for no reason during gameplay and then sometimes reappear briefly....seems like it's a bug.

  • \$\begingroup\$ This is often done by listening for a "window focused" event and re-applying your custom cursor whenever it happens. Do you have something like this in LibGDX you can listen for? \$\endgroup\$
    – DMGregory
    Commented Jun 30, 2020 at 10:19
  • \$\begingroup\$ @DMGregory♦ Ok good thought, I did some searches and there is Display.isActive() although not sure if that exists anymore since it can't be found in any possible imports when I add it. Although if you check my 'edit' at the bottom of my question it seems there is a bigger problem, it seems to actually be a bug where the cursor reverts to default even without un-focusing the window. \$\endgroup\$
    – Hasen
    Commented Jun 30, 2020 at 10:27


You must log in to answer this question.

Browse other questions tagged .