custom_mouse_cursor.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. .. _doc_custom_mouse_cursor:
  2. Customizing the mouse cursor
  3. ============================
  4. You might want to change the appearance of the mouse cursor in your game in
  5. order to suit the overall design. There are two ways to customize the mouse
  6. cursor:
  7. 1. Using project settings. This is simpler, but more limited.
  8. 2. Using a script. This is more customizable, but involves scripting.
  9. .. note::
  10. You could display a "software" mouse cursor by hiding the mouse cursor and
  11. moving a Sprite2D to the cursor position in a ``_process()`` method, but
  12. this will add at least one frame of latency compared to a "hardware" mouse
  13. cursor. Therefore, it's recommended to use the approach described here
  14. whenever possible.
  15. If you have to use the "software" approach, consider adding an extrapolation step
  16. to better display the actual mouse input.
  17. Using project settings
  18. ----------------------
  19. Open the **Project Settings** and go to **Display > Mouse Cursor**. You will see the settings
  20. :ref:`Custom Image <class_ProjectSettings_property_display/mouse_cursor/custom_image>`,
  21. :ref:`Custom Image Hotspot <class_ProjectSettings_property_display/mouse_cursor/custom_image_hotspot>`,
  22. and :ref:`Tooltip Position Offset <class_ProjectSettings_property_display/mouse_cursor/tooltip_position_offset>`.
  23. .. image:: img/cursor_project_settings.webp
  24. **Custom Image** is the desired image that you would like to set as the mouse cursor.
  25. **Custom Hotspot** is the point in the image that you would like to use as the cursor's detection point.
  26. .. warning::
  27. The custom image **must** be 256×256 pixels at most. To avoid rendering
  28. issues, sizes of 128×128 or smaller are recommended.
  29. On the web platform, the maximum allowed cursor image size is 128×128.
  30. Using a script
  31. --------------
  32. Create a Node and attach the following script.
  33. .. tabs::
  34. .. code-tab:: gdscript GDScript
  35. extends Node
  36. # Load the custom images for the mouse cursor.
  37. var arrow = load("res://arrow.png")
  38. var beam = load("res://beam.png")
  39. func _ready():
  40. # Changes only the arrow shape of the cursor.
  41. # This is similar to changing it in the project settings.
  42. Input.set_custom_mouse_cursor(arrow)
  43. # Changes a specific shape of the cursor (here, the I-beam shape).
  44. Input.set_custom_mouse_cursor(beam, Input.CURSOR_IBEAM)
  45. .. code-tab:: csharp
  46. using Godot;
  47. public partial class MyNode : Node
  48. {
  49. public override void _Ready()
  50. {
  51. // Load the custom images for the mouse cursor.
  52. var arrow = ResourceLoader.Load("res://arrow.png");
  53. var beam = ResourceLoader.Load("res://beam.png");
  54. // Changes only the arrow shape of the cursor.
  55. // This is similar to changing it in the project settings.
  56. Input.SetCustomMouseCursor(arrow);
  57. // Changes a specific shape of the cursor (here, the I-beam shape).
  58. Input.SetCustomMouseCursor(beam, Input.CursorShape.Ibeam);
  59. }
  60. }
  61. .. seealso::
  62. Check :ref:`Input.set_custom_mouse_cursor() <class_Input_method_set_custom_mouse_cursor>`'s
  63. documentation for more information on usage and platform-specific caveats.
  64. Cursor list
  65. -----------
  66. There are multiple mouse cursors you can define, documented in the
  67. :ref:`Input.CursorShape <enum_Input_CursorShape>` enum. Which ones you want to use
  68. depends on your use case.