Customizing the mouse cursor

You might want to change the appearance of the mouse cursor in your game in order to suit the overall design. There are two ways to customize the mouse cursor:

  1. Using project settings. This is simpler, but more limited.

  2. Using a script. This is more customizable, but involves scripting.

Note

You could display a “software” mouse cursor by hiding the mouse cursor and moving a Sprite2D to the cursor position in a _process() method, but this will add at least one frame of latency compared to a “hardware” mouse cursor. Therefore, it’s recommended to use the approach described here whenever possible.

If you have to use the “software” approach, consider adding an extrapolation step to better display the actual mouse input.

Using project settings

Open the Project Settings and go to Display > Mouse Cursor. You will see the settings Custom Image, Custom Image Hotspot, and Tooltip Position Offset.

../../_images/cursor_project_settings.webp

Custom Image is the desired image that you would like to set as the mouse cursor. Custom Hotspot is the point in the image that you would like to use as the cursor’s detection point.

Warning

The custom image must be 256×256 pixels at most. To avoid rendering issues, sizes of 128×128 or smaller are recommended.

On the web platform, the maximum allowed cursor image size is 128×128.

Using a script

Create a Node and attach the following script.

GDScriptC#

  1. extends Node
  2. # Load the custom images for the mouse cursor.
  3. var arrow = load("res://arrow.png")
  4. var beam = load("res://beam.png")
  5. func _ready():
  6. # Changes only the arrow shape of the cursor.
  7. # This is similar to changing it in the project settings.
  8. Input.set_custom_mouse_cursor(arrow)
  9. # Changes a specific shape of the cursor (here, the I-beam shape).
  10. Input.set_custom_mouse_cursor(beam, Input.CURSOR_IBEAM)
  1. using Godot;
  2. public partial class MyNode : Node
  3. {
  4. public override void _Ready()
  5. {
  6. // Load the custom images for the mouse cursor.
  7. var arrow = ResourceLoader.Load("res://arrow.png");
  8. var beam = ResourceLoader.Load("res://beam.png");
  9. // Changes only the arrow shape of the cursor.
  10. // This is similar to changing it in the project settings.
  11. Input.SetCustomMouseCursor(arrow);
  12. // Changes a specific shape of the cursor (here, the I-beam shape).
  13. Input.SetCustomMouseCursor(beam, Input.CursorShape.Ibeam);
  14. }
  15. }

See also

Check Input.set_custom_mouse_cursor()‘s documentation for more information on usage and platform-specific caveats.

Cursor list

There are multiple mouse cursors you can define, documented in the Input.CursorShape enum. Which ones you want to use depends on your use case.


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.

Previous Next