Issue with ios device render resolution

Hello, I hope this is the right section…

So… I’m confused on how to display properly things on iOS devices (specifically testing on an iPhone 14 iOS 16).

I have a mobile game project running fine on the engine window (720x1280).

For instance the gui element labeled InGame is positioned at:

x = window.get_size().width /2, y = window.get_size().height /2

But when I deploy on the iPhone the position is way off:

I have set the display profile like this:

But it seems the resolution is still the phone native one (2532 × 1170).

What am I doing wrong?

In this case, you shouldn’t rely on window size, instead, use display size which you can get by

local display_width = sys.get_config_int("display.width")
local display_height = sys.get_config_int("display.height")

Thank you for the reply… that seems working :slight_smile:

Strangely, on Windows I found incorrect values ​​with sys.get_config_int(“display.width”) and sys.get_config_int(“display.height”). This gave me values ​​configured in game.project that did not match the correct size.

But I got the correct values ​with ​window.get_size().

This is how it is suppose to work, you are getting value from game.project?

These are two different things

2 Likes

Yes

I had trouble thinking one thing was another. Good thing now it’s clear to me what each thing is for. Thanks!

1 Like

How come when I rotate the device to landascape the width and height are same as in portrait mode?
Even though I set different res depending on landscape/portrait?

so when rotating horizontally, I still get width 720 when checking sys.get_config_int(“display.width”)?

I’m not sure what Display Profiles is using for but the right place for setting display size is at Display section of game.project file

Thank you, I was looking at it and it seems very useful thing to use for some GUI elements. But the thing I still don’t understand is what exactly then Display Profiles do?

For instance

sys.get_config_int(“display.width”)

Gets the width defined in game.project->Display-width

How do I reference from code the width defined in Display Profiles? I thought it was the same value, but maybe I’m wrong?

Display Profiles define certain thresholds of screen ratios that are checked by the GUI system to change layout of a GUI (for instance going from portrait to landscape):

1 Like

ahh I see, it’s only used from the GUI system then… gotcha :slight_smile:

so what would be the best approach to define different resolutions for different devices and orientation?

Like for instance I want the app to have windows set as follows:

on iPhone portrait 720x1280, landascape 1280x720
on iPad postrait 1080x1920, landscape 1920x1080

Hope it makes sense?

1 Like

You can’t control the window size on mobile. The window is the entire screen and will be sized according to the size of the display panel. A call to window.get_size() will return the actual size of the device it is running on.

BUT I think we need to come back to your initial post again:

This is not the right way to go about things when positioning GUI elements. You should position GUI elements according to the size set in game.project. If you have game.project display width and height of 640x1136 and want a GUI box node positioned dead center on the screen you set the position of the box node to 320x568.

When you launch the game the GUI will automatically adjust itself to the physical resolution of the device, but if something is positioned in the center it will remain in the center regardless of screen resolution. If you anchor something to the bottom or top it will remain there regardless of the height of the screen. And so on. The GUI will adjust to the physical dimensions according to the rules defined in the manual: GUI scenes in Defold

If you create a GUI node at runtime and want to position it in the center of the screen you need to use the display width and height, not the window width and height. So in your code it would be

x = sys.get_config_int("display.width") / 2 /2, y = sys.get_config_int("display.height") / 2 /2

Wow! I hadn’t noticed that this setting was only for the GUI.

Thank you! That’s clear now :slight_smile:
I’ve setup 2 layouts for portrait and landascape and assigned them to the GUI scene and all seems working fine. Though I don’t understand this:

I’m drawing a bounding box around the card node (just a box node with a texture assigned, same for both landscape and portrait layouts), using the msg.post("@render:", “draw_line”) and the gui.get_position and gui.get_size properties. On portrait it looks okay:

But when I rotate the device to landscape mode, the bounding box gets drawn in a wrong position and with wrong size:

Any idea why that’s happening?

The strange thing is also that when testing the builtin function gui.pick_node inside on_input, the action x and y seem getting a proper hit inside the card node.

How is the bounding box positioned? Is it a child node of the card?

The bounding box is just composed by 4 lines drawn with msg.post("@render:", “draw_line”) call, using the card node position and size (gui.get_position and gui.get_size)

the lines draw calls are all inside the update function.

Oh, ok, that will be a bit complicated. Debug lines are mostly useful when drawing lines in the game world and aligning with game objects. The GUI is different and as I told you before it will adjust itself to the screen resolution. The position you get from gui.get_position() will be in the coordinate space of the screen dimensions set in game.project while debug lines are in the actual screen size dimensions.

Thank you… I’m starting I think to get my head around this :slight_smile:

1 Like

Me again heheh

So I got mostly everything working nicely on iPhone, but today I tried to add another qualifier to the display profiles to see how it would handle a different resolution on a different device.

But when I deploy on the iPad air 4 it seems always picking the iPhone resolution qualifier.

Any suggestion?