how to detect screen size or screen radio during runtime ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By socheat.khauv
:warning: Old Version Published before Godot 3 was released.

how to check screen size or screen radio on the runtime device, (android, iphone, ipad) … ?

and set the camera2d projection to a desired size ?

for example

if radio is 5x3 i would like to have camera2d size at 500x300

if radio is 7x5 i would like to have camera2d size at 700x500

:bust_in_silhouette: Reply From: Zylann

The camera is already supposed to do this according to your project settings.
Take a look at Scene -> project settings -> Display -> stretch mode and stretch aspect.
http://docs.godotengine.org/en/latest/tutorials/engine/multiple_resolutions.html#doc-multiple-resolutions

Scene → project settings → Display

is it possible to set display width and height value during runtime ?

socheat.khauv | 2016-07-23 19:41

You don’t really need to, these settings are supposed to do that automatically for you. Did you tried the “2d” stretch mode?
The only difference on mobile is that you have a fixed resolution. It’s like having a window that you can’t resize (so in the end you can test it on PC, it works the same).
Other than that, I don’t understand what is the actual problem that leads you to ask this question :stuck_out_tongue:

Zylann | 2016-07-23 19:46

The problem is that.

now I am testing on Google Nexus 4,
its screen size is 1280x768
which has ratio of 5x3

Scene → project settings → Display
if I set width and height, 800x600 (4x3), and maintenance radio scale by either horizontal or vertical,
it will show a black bar some how horizontally or vertically direction.

and I don’t want to have that black bar and also want to to scale without losing radio

That why I would like set (Scene → project settings → Display width and height during runtime)

I will do calculation to find its width and height. in my example cases
it will be 800x480.

socheat.khauv | 2016-07-23 20:25

Oh… I see, the problem is the black margins then?
If you set stretch_mode to disabled and stretch_aspect to ignore, resizing the window will simply change the resolution of the cameras.

If you need to keep it centered, you can reset the position of the camera to whatever you need it centered on. Just in case, there is a size_changed signal in Viewport that you can listen to.

Otherwise, there is an issue related to this Add an extra stretch mode for a "safe zone" on mobiles · Issue #5776 · godotengine/godot · GitHub

Zylann | 2016-07-23 20:47