Viewport display different screen size when running on Android Device

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By emiltan97


My goal is to implement a constantly diminishing timebar on the top of the screen that fits all screen sizes. For example, the default window width of my game is 1280 px. If its on a wider screen such as 1600 px, the time bar should be longer and should diminish in a faster rate.

My attempt for the solution is to scale up the time bar with the ratio between the current viewport width to the default window width. Then adjust the position of the timebar by an offset which is calculated from the difference between the current viewport width and the default window width.

$ComboBar.rect_scale.x = $ComboBar.rect_scale.x*(get_viewport().size.x/1280)
$ComboBar.rect_position.x = $ComboBar.rect_position.x - ((get_viewport().size.x-1280)/2)


The attempt works perfectly fine when playtested with different test window size on my Windows machine. However when I export to the Android device, the timebar was appeared as longer than the screen width. I tried to print the window size of my Android device which is 2400 px wide.

(2400, 1080)

I tried printing the position of a notifier when exiting the screen and it shows


respectively, which I assume that the view port size of theA Android device does not match the actual view port size shown. The Android device used is Samsung Galaxy S20.

Does anyone face similar issue? Any help is much appreciated!

:bust_in_silhouette: Reply From: Calinou

Godot already provides a 2D scaling system, so you do not need to move or resize GUI elements manually. See Multiple resolutions in the documentation.