Mobile screen width and height

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

Hi. I am working a mobile game project. And i don’t know to setting the width and the height.
Game width = 1000
Game height = 800
Mobile phone width = 600
Mobile phone height = 600
If I run the game on this phone, all sprites get fail. So the height and width of all scprites change.

How should I do this adjustment? Thanks…

Like Anm said, make sure to use anchored positions irregardless of screen size
Also when targeting mobile platforms its a good idea to get that device’s screen size using OS.get_real_window_size() then adjusting your game’s aspect ratio to match as there are so many different ones

Wakatta | 2021-01-28 01:37

:bust_in_silhouette: Reply From: Anm

Are your top level controls anchored to the viewport appropriately? Check this tutorial:

Have you tried layouts and/or containers? Another tutorial:

He didn’t exactly answer my question, but he gave me an idea.if I can get the size of the mobile phone, i can do the {GameSize/MobilePhone}. And I can resize all sprites this proportion.
How i get phone size? Thanks …

tncft4 | 2021-01-28 02:10

Your question didn’t really detail what “adjustment” you were expecting, so…

Regardless, see Viewport.size.

There is also OS.get_screen_size() but that is probably not what you want, due to the possibility of other things being on screen.

Anm | 2021-01-28 02:30

:bust_in_silhouette: Reply From: Calinou

Follow the Multiple resolutions documentation. in a nutshell:

  • Set the project window size to 1280×720 in the Project Settings (or 720×1280 for a game played in portrait mode). This is a common baseline resolution for mobile, but you can also use 1920×1080 (1080×1920 in portrait) for crisper visuals at the cost of larger file sizes.
  • Set the stretch mode to 2d and stretch aspect to expand in the Project Settings.
  • Configure your UI nodes’ anchors correctly so they are moved depending on the device’s aspect ratio.
  • Make sure UI elements don’t touch the screen edges to avoid issues with notches and some devices’ curved borders.
1 Like