How to obtain screen resolution in pixels as floats/integers?

I need the screen resolution of the active mobile device to make sure that the camera works as intended (=shows the complete background in fullscreen) and to make sure that every sprite, volume and player are scaled accordingly. To clarify the latter, my sprites have certain sizes for example my background is 1920px by 1080px which is not large enough for some mobile devices, so these sprites have to be scaled. I tried two methods (the 2nd method is illustrated using the disconnected nodes at the bottom). These work in the selected viewport, however not in ‘play in new window’ mode and with my own mobile device. “Does not work” means a black screen with a tiny bar in the center of the screen (=background). This happens due to the fact that the “Get viewport size” returns zero which means that the actor scale is 0 1 0.

In conclusion I need a method which determines the resolution of the active mobile screen. For example, if I play on a device with a resolution of 1920 1080 px then the node should return x=1920px and y=1080px.

(Default X & Y are the lengths of the sprite)

Solved this by adding a small delay (0.01s)

1 Like