Mouse cursor in the center of the sprite

Godot Version

Godot 4

Question

Hi, I have this code

extends Sprite2D

func _ready():
  Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
  var mouse_position = Vector2(position.x, position.y)
  Input.warp_mouse(mouse_position)

The window size is 640x360, full screen mode. The resolution of my screen is 1920x1080.
In windowed mode the mouse cursor moves to the center of the sprite, but in full screen mode it goes a little higher and to the right. If I print mouse_position in full screen mode it is a vector (344, 88), but if I print get_global_mouse_position() at startup it is a vector (114.572, 29.38776). I can’t figure out why this is happening…

I solved the problem like this
get_viewport().warp_mouse(mouse_position)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.