Topic was automatically imported from the old Question2Answer platform.
Asked By
bleistift
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.
func _ready():
# this line confines the cursor to the game window
Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
# 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
Input.set_custom_mouse_cursor(load("res://transparent.png"))
func _process(delta):
# this sets the nodes position to the mouse position each frame
globalposition = get_viewport().get_mouse_position()
I managed to get my similar thing working with set_global_position(get_viewport().get_mouse_position())
Also you can change Mouse settings in a node to ignore it