0 votes

Hi. I am working a mobile game project. And i don't know to setting the width and the height.
Example:
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...

in Engine by (21 points)

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

2 Answers

0 votes

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

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

by (23 points)

Hi,
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 ....

Your question didn't really detail what "adjustment" you were expecting, so...

Regardless, see Viewport.size.

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

+2 votes

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.
by (12,343 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 Frequently asked questions and 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.