I have a RigidBody2D and an Area2D in my project. I want to do something when these nodes are clicked. I want to know how can I change mouse shape (to default hand shape) when the mouse is hovered these nodes. I found this function: set_default_cursor_shape, but it only works on special nodes. Is there any method that can be used to change mouse cursor shape?
change mouse cursor to hand when hover RigidBody2D or Area2D
- Edited
You can use a custom cursor by doing something like this:
Create a sprite with a texture that you want to change to (hand or any custom design) and set it hidden by default.
Add a CollisionShape2D
or a CollisionPolygon2D
to your Area2D
object(s), and wire the events up to trigger hiding the mouse cursor and showing your own on entering the area, have the movement event move your custom MouseSprite
around while the cursor is within the area, and restoring the original upon exit, such as:
func _on_Area2D_mouse_enter():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
get_node("MouseSprite").show()
func _on_Area2D_mouse_exit():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_node("MouseSprite").hide()
func _on_Area2D_input_event( viewport, event, shape_idx ):
var mouse_pos = get_viewport().get_mouse_pos()
get_node("MouseSprite").set_pos(mouse_pos)
Thanks. I don't want to use my own sprite for mouse shape. There are some default mouse shapes that are commonly used by many apps or games. How can I use theme?
- Edited
Removed because I can't read…
I am also having this issue. I want to be able to make the mouse cursor become the system's default "grabbing hand."
The function set_default_cursor_shape(CURSOR_---) should do the job.