I have a project with a display size of 2160x1080 but the debug custom resolution is set to 1080x540. I first check size with print(window.get_size()) in main.script and it returns display size, not the custom size. Then I load a proxy level collection where I check again size in its own script and returns custom size.
The issue for me happens when I dynamically position a game object in the middle of screen of the proxy level, it calculates using the custom size but positioned as it was the display size. So “middle” is 1/4 the width and 1/4 the height of the screen.
Also I use msg.post("@render:", "use_fixed_fit_projection") in main.script.
Any idea what am I doing wrong? Thanks in advance.
Of course. I made a little test project: adaptive-test.zip (190.9 KB)
This test has a 1920x1080 size. In order to see the issue you have to change the debug set resolution to another size, in this case 960x540. And build it to see how the loaded proxy level is not centered.
Defold is already scaling the screen and coordinates itself, you don’t have to do that manually, or you scale them twice to a wrong value.
If your game is set to 1920x1080, then (1920, 1080) is always the top right corner, and (960, 540) is always the center, even if you resize the window.
You can use window.get_size() to react to the windows size, or if you use a custom camera that does not scale automatically. But if you just want to center an object, you can either hardcode it:
local WIDTH, HEIGHT = 1920, 1080
or read it from the game.project file:
local WIDTH = sys.get_config_int("display.width")
local HEIGHT = sys.get_config_int("display.height")
I was trying to get game objects to adapt to any screen size. So it’s not clear to me yet if that is possible without using GUI elements and display profiles. I would like the app to adapt to any size from a small resolution mobile app to a 4k TV. I’m currently testing with camera components. Let’s see how it goes.