Mouse and input coordinates¶
The reason for this small tutorial is to clear up many common mistakes about input coordinates, obtaining mouse position and screen resolution, etc.
Hardware display coordinates¶
Using hardware coordinates makes sense in the case of writing complex UIs meant to run on PC, such as editors, MMOs, tools, etc. However, it does not make as much sense outside of that scope.
Viewport display coordinates¶
Godot uses viewports to display content, and viewports can be scaled by several options (see Wiele rozdzielczości tutorial). Use, then, the functions in nodes to obtain the mouse coordinates and viewport size, for example:
Alternatively, it's possible to ask the viewport for the mouse position:
When the mouse mode is set to
event.position value from
InputEventMouseMotion is the center of the screen. Use
event.relative instead of
event.speed to process mouse movement and position changes.