0 votes

I have a Control. When the mouse cursor hovers over the Control it has the shape "Can Drop" (an open hand) that I configured with the inspector panel - so far so good. When the Control is clicked, I want the cursor to immediately change to to "Drag" (closed hand). And I'd like the reverse to happen immediately when the mouse button is released.

As far as I can tell, I can only change the cursor from script by calling set_default_cursor_shape(...). But it doesn't seem to take effect until the mouse moves. It's probably fine for now but I'd like the cursor shape to change right away. Is there some way to do that? Here's my Control's entire script:

extends Control

var start_mouse: Vector2
var start_pos: Vector2
var dragging = false

func _on_Item_gui_input(event):
    if event is InputEventMouseButton:
        dragging = event.pressed
        if dragging:
            start_pos = self.rect_position
            start_mouse = get_global_mouse_position()
            self.set_default_cursor_shape(Control.CURSOR_DRAG)
        else:
            self.set_default_cursor_shape(Control.CURSOR_CAN_DROP)
    elif event is InputEventMouseMotion:
        if dragging:
            self.set_position(get_global_mouse_position() - start_mouse + start_pos)
Godot version v3.4.3.stable.official [242c05d12]
in Engine by (12 points)

Open project settings, go to Display>Mouse Cursor. There should be Custom Image. That is where your image goes Custom image hotspot is your cursors detection point. The custom image must be less than 256x256.
This is from godot official docs and it worked for me.

Thanks perolegenda, but that didn't help. I tried setting a custom image in the project settings as you suggested, but it doesn't affect how quickly the cursor visibly changes when setting a cursor from a script - it still needs the mouse to move before it changes.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.