In-game resolution configuration and different aspect ratios

I’m working on the configurations and settings for my game. My current issues are with resolution handling.

What I want is to be able to detect the user’s screen resolution and use that, if possible. If not, I can create a configuration scene. I would like it best if it could auto-detect so there’s less for the user to configure before getting to play.

I’m also wanting to support different aspect ratios. My game is being designed in 1920x1080 (16:9), but a lot of people might also be using 8:5 / 16:10. That would stretch the graphics vertically, which I really don’t want. So could someone explain how I can add padding or margins so it doesn’t get stretched?

It could be a bug actually, but if you run your game in Window mode, the ScreenWidth() and ScreenHeight() expressions returns the actual desktop resolution in native game (in full screen it returns the game screen size).

So what you can do is, run your game in window mode at the beginning and get the desktop resolution using the expressions and store it inside a variable and then, change the screen size using the value of the variables and switch to full screen.

This way, the screen size is going to be the same as the desktop resolution but the actual screen resolution is remain the original and the screen is going to be scaled only. When you change the screen size, the option on the bottom “Use this size as default size for camera” should change the resolution (camera size) I believe but doesn’t work for me so the actual resolution is not changed automatically. but screen size

To change the resolution along with the size of the screen, you also need to change the camera size manually to be the same as the screen size using the same variables. But, in case you change the camera size more area of your scene going to be visible, so you need to keep that in mind when you design your scenes and GUI.
Finally, because you change the size of the camera, it position is going to be changed as well.

To solve this, get the X and Y position of the camera using the CameraX("",0) and CameraY("",0) expressions and store it inside variables before you change camera size. And apply the position after you have changed the size of the camera.

So the solution is looks like this in order:

First, get desktop resolution:

At the beginning of the scene: Activate full screen : no DesktopWidth = ScreenWidth() DesktopHeight = ScreenHeight()

After, change screen size to be the same as the desktop resolution and then switch to full screen:
Make sure it is executed only 1 time and not every frame.
And make sure you change the screen size first and then switch to full screen.
Personally I hate it when games starts in small screen, move my gadgets and icons on the desktop and every time when I quit the game, I need put my icons and gadgets back where they were. To avoid that, change the screen size first.

Trigger Once: Change screen size : DekstopWidth, DesktopHeight Activate full screen : yes

After, change screen resolution to be the same as the desktop resolution:
Make sure it is executed only 1 time and not every frame.

Trigger Once: CameraX = CameraX("",0) CameraY = CameraY("",0) Change Camera size : DesktopWidth, DesktopHeight Camera X position : CameraX Camera Y position : CameraY

It’s not entirely a bug, but I think I would call it more of a compatibility issue. I’m thinking that when a game is ran in fullscreen, it will change the desktop’s resolution to whatever the game is running. So, it’s not reporting wrong information, it’s just that the information has changed.

As for the rest, I’ll have to try it out later. Hopefully I’ll be able to find someone to help me test it at different aspect ratios. All of the screens I have access to are 16:9. I didn’t realize ScreenWidth() and ScreenHeight() we in the expression editor.

My original thought was if someone uses something like 1920x1200 (8:5), the game would actually run at 1920x1080 (16:9) and have 110 padding at top and bottom since the game is already kind of bordered in black. Most scenes center the camera on an object, so positioning shouldn’t be a problem. My concern is keeping pathfinding and creating objects, which both use X;Y positions, intact. Does it change these coordinates when the camera size is changed?

No, the coordinate system does not change.
But there is a few things that need to consider if you want to change the camera size.
Originally, you might see only 800 pixels of your scene, if you change the camera width to be 1000, you are going to see 1000 pixels of your scene.
If you create an object in position 400 for example and the camera position is in the middle of the screen, in case the camera width is 800 pixels the object at position 400 is going to be at the middle of the screen.
In case the camera width is 1000 pixels the object at position 400 is going to move from the middle since the middle of the screen changed to 500.
Also if you create an object at position 900 for example, it might not visible if the camera size is 800 and the camera position is in the middle but it is going to be visible if the camera size is 1000.
Just keep this mind if you want to use different camera sizes/ screen resolution.

In my opinion could be better if you would target only a few resolution that works with your game, and simply apply the higher targeted resolution possible.

Just an example, you could target let say:

1024x768
1280x1024
1680x1050

And check at the beginning of the game.
If DesktopWidth >= 1680 and DesktopHeight >=1050 use 1680x1050 otherwise, check lower resolution and use tha highest possible to make sure the player is not going to use too high resolution and may see too much of the scene maybe even empty areas or areas that supposed to be not visible. You could also define a maximum resolution to avoid that.

Really, in case you want to support many and any resolutions, the best way to go is to use % based coordinates instead of pixel based but I don’t think GDevelop supports % based coordinates out of the box, you need to calculate that yourself using math expressions.

EDIT://

You can run your game in window and change the window and resolution size to whatever you want, if it looks okay in window, probably it looks okay in full screen. But in case you want I can help, I have a 16:10 screen with maximum resolution of 1680x1050.

1 Like

I designed the game at 1920x1080, which was the highest resolution I planned on working with. Scaling down to other 16:9 resolutions has worked out perfectly so far.

Using your 1680x1050 as an example, I should be able to scale it to 1680x946, which is 16:9 (+1 pixel so it’s not an odd number) and change the camera to 1050, I think getting it that close before changing the camera should make it a little more forgiving for screen position since most scenes are centered on either the main character or another object like a message panel with options or a town map. The screenshots show what I’m working with. There’s already black all around, so as long as what I’m wanting the camera focused on stays centered and the traps and treasure chests get created in the right spots, it should be fine.


I’m sorry. I think I was over-complicating things yesterday. I was dealing with an eye infection and my eyes couldn’t focus on anything, so I was struggling with reading what you said. My eyes are a little better today, so I’ll get back to work and just go through some trial and error to see if I can make it look good at 16:10 resolutions.