+1 vote

My goal is to move a node with the mouse, but without having a mouse pointer that can leave the window or is shown or can be stuck at the border of the window.

How this should work for the user:
The user starts the game and the mouse pointer dissappers. He could move the node by just moving the mouse. If he want to use other programs than the game, he has to pause the game, close it or switch to another window with ALT-TAB.

in Engine by (15 points)

1 Answer

+2 votes

Attach this script to your node:

func _ready():
    # this line confines the cursor to the game window

    # this line replaces the cursor image with a different image
    # that image can be 250x250 pixels large at max and (in our
    # case) is fully transparent to hide the actual cursor

func _process(delta):
    # this sets the nodes position to the mouse position each frame
    globalposition = get_viewport().get_mouse_position()
by (10,327 points)

Thank you very much! That works great!

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 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 webmaster@godotengine.org with your username.