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?
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):
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
Thank you! That’s clear now
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:
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.
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.
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.