Godot: Stretch Mode 2D, Mouse Position scaled incorrectly

Created on 30 Jul 2019  路  5Comments  路  Source: godotengine/godot

Godot version:
Release 3.1.1 (Latest)

OS/device including version:
Windows 10

Issue description:
My project is configured at the resolution 1600x900.
When the project is scaled up (I.E Fullscreen) the Viewport size is increased to 1920x1080. However, if the mouse is moved to the bottom right, the value is about 1600,900 (Actually around half a pixel less)

Note: If this is not a bug:
Documentation of Viewport states that the mouse position is relative to the viewport...
image

Steps to reproduce:
Make a brand new project, change the stretch mode to 2D.
Write a script that prints the mouse position.
Scale the window and check what the mouse position is claimed to be.

Minimal reproduction project:
Test.zip

bug confirmed core input

All 5 comments

I have the same issue with scale to viewport as well. Not only 2d.
OS is Kubuntu 19.04 though.

There is a way to get an "unscaled" coordinate by dividing it with some method with stretch in the name. (I'm on mobile right now, I don't remember the name.)

get_viewport().warp_mouse() has different behaviour than get_mouse_position(); the former is actually relative to the Viewport, but the latter is not

There is a way to get an "unscaled" coordinate by dividing it with some method with stretch in the name. (I'm on mobile right now, I don't remember the name.)

@Calinou could you please tell the method name and what you did? I'm curious if that would lead to a usable workaround in the meantime.

@SGMcejo This seems to work:

var unscaled_mouse_position = get_viewport().get_mouse_position() / get_viewport().get_size_override() * OS.window_size

Test project (displays scaled and unscaled coordinates for comparison): test_mouse_coords.zip

Was this page helpful?
0 / 5 - 0 ratings