0 votes

Goal

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.

Attempt

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)

Issue

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

-200
1500

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!

Godot version godot 3.3.3
in Engine by (14 points)

1 Answer

0 votes

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.

by (10,950 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.