custom_mouse_cursor.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .. _doc_custom_mouse_cursor:
  2. Customizing mouse cursor
  3. ========================
  4. 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:
  5. 1. Using project settings
  6. 2. Using a script
  7. Using project settings is a simpler (but more limited) way to customize the mouse cursor. The second way is more customizable, but involves scripting.
  8. Using project settings
  9. ----------------------
  10. Open project settings, go to Display>Mouse Cursor. You will see Custom Image and Custom Image Hotspot.
  11. .. image:: img/cursor_project_settings.png
  12. Custom Image is the desired image that you would like to set as the mouse cursor.
  13. Custom Hotspot is the point in the image that you would like to use as the cursor's detection point.
  14. .. note:: The custom image **must** be less than 256x256.
  15. Using a script
  16. --------------
  17. Create a Node and attach the following script.
  18. .. tabs::
  19. .. code-tab:: gdscript GDScript
  20. extends Node
  21. # Load the custom images for the mouse cursor.
  22. var arrow = load("res://arrow.png")
  23. var beam = load("res://beam.png")
  24. func _ready():
  25. # Changes only the arrow shape of the cursor.
  26. # This is similar to changing it in the project settings.
  27. Input.set_custom_mouse_cursor(arrow)
  28. # Changes a specific shape of the cursor (here, the I-beam shape).
  29. Input.set_custom_mouse_cursor(beam, Input.CURSOR_IBEAM)
  30. .. code-tab:: csharp
  31. public override void _Ready()
  32. {
  33. // Load the custom images for the mouse cursor.
  34. var arrow = ResourceLoader.Load("res://arrow.png");
  35. var beam = ResourceLoader.Load("res://beam.png");
  36. // Changes only the arrow shape of the cursor.
  37. // This is similar to changing it in the project settings.
  38. Input.SetCustomMouseCursor(arrow);
  39. // Changes a specific shape of the cursor (here, the I-beam shape).
  40. Input.SetCustomMouseCursor(beam, Input.CursorShape.Ibeam);
  41. }
  42. .. note::
  43. Check :ref:`Input.set_custom_mouse_cursor() <class_Input_method_set_custom_mouse_cursor>`.
  44. Demo project
  45. ------------
  46. Find out more by studying this demo project:
  47. https://github.com/guilhermefelipecgs/custom_hardware_cursor
  48. Cursor list
  49. -----------
  50. As documented in the :ref:`Input <class_Input>` class (see the **CursorShape** enum), there are multiple mouse cursors you can define. Which ones you want to use depends on your use case.