GML Adapt room to display size

AcrobatEpee

Member
Hello, I, in my game, have a code that spawns squares depending on the area I enter in two variables : draw_area_width & draw_area_height.

The problem I have is that I want these variables to be set to the display width and so get them to draw squares in all the width of the screen.

My room is 1080x1920 by default, and once tested on a 1125x2436, this is the result I get after setting both my variables to display_get_width(). You can see the last square on the right is cut.

My game is set to Full Scale, I tried setting the room size to the display size which did not work.

I am coming to you guys to know if someone could tell me what should I change in order to get my squares to fill the width perfectly and in order to be able to see them on any device. If you can and are willing to help in a more personnal way, my discord is open and I will be very thankful. This is my final step before releasing my game and I've been stuck on it for days now. Thanks for considering. :)


Discord : AcrobatEpee#3854
 
K

ktiix

Guest
In your screenshot, the squares are also stretched a bit vertically. But fixing your issue will fix that.

When you set up your game, you should set your draw_area_width and draw_area_height according to the display size and the aspect ratio you want.
Your rooms are 1080x1920, which is 16:9, or 1.778. You need to find the ratio of the display. The common way is to have the longer side on top of the ratio. 1125x2436 is 19.5:9 or 2.165. This is a taller ratio than your rooms, so your sides are getting clipped off. You need to choose between clipping off part of your game, or having black bars (in this case they will be top and bottom).

You should also handle having a smaller aspect ratio than the 16:9 that is optimal, in which case the calculations all get flipped.

For a larger ratio (1125x2436) you will set the smaller of your dimensions to be the smaller of the display dimensions, ie draw_area_width = display_get_width()
Then the other dimension is scaled by your aspect ratio, ie draw_area_height = draw_area_width * 16 / 9 (which will give 2000 - it fits)

You will also need to offset your drawing if you want the padding to be equal on the top and bottom;
draw_y_offset = (display_get_height() - draw_area_height) / 2

For a smaller screen ratio, the y offset will be zero and you'll need instead an x offset. The draw height will equal the display height, and the draw width will be scaled by your aspect ratio.

I hope all that makes sense and works!
 

AcrobatEpee

Member
Last edited:
Top