• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android Adjust room height based on device?

So I have a small project with 3 rooms. Room size is 480x320 pixels. No views/cameras are used.
Of course, since devices differ in width & height, the game will look stretched out on some of them.
Is there a neat way of handling the aspect ratio to make the game fit most screens?
Now, changing the width of the rooms would cause issues with the gameplay, but changing the room height would do no harm.
I was thinking of using display_get_gui_width() to change the height of the room (using width since the game is in landscape mode).
But if I understand correctly, the gui_width is based on the size of the device, which I guess can be very high (thousands of pixels)? I don't think it would be a good result to have the game be 480x1000+ pixels.

Is there some neat formula or the like to handle this?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Use a view camera and set it to the room width then scale the height to the device. So, on game start you get the size of the display, then activate the view[0] and set the port width and height to the DISPLAY size, then you set the camera width to the width you want (480), and set the camera height to the relative height of the display based on the display aspect ratio (you get the aspect ration by doing display width/height, then get the camera height by doing 480/ratio).
 

Ommn

Member
this codes working for me:
GML:
var __ratio=display_get_height()/display_get_width();
room_height=480*__ratio;
surface_resize(application_surface,room_width,room_height);
 
this codes working for me:
GML:
var __ratio=display_get_height()/display_get_width();
room_height=480*__ratio;
surface_resize(application_surface,room_width,room_height);
Interesting. Is that code adjusted when the game is in landscape mode, or do I need to switch place on display_get_width & display_get_height in __ratio?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
That code won't do what you want... It just sets the app surface, which will then be drawn stretched/squashed to fit the room/camera/port. You can have a room that is 320x180, but set the app surface to 1920x1080 and all you're doing is getting 6x pixel density, not changing how those pixels will be rendered. You need to set the port and the camera as I explained above.
 

Ommn

Member
That code won't do what you want... It just sets the app surface, which will then be drawn stretched/squashed to fit the room/camera/port.
he is need room_width is constant and room_height will change to match its size with the size of the mobile.

drawn stretched/squashed.
why?
This can happen when you change the size of the surface "application_surface" and do not change the size of the room.

But the above code will make the ratio between the height and width of the screen equal to the ratio between the height and width of the room.

I know that this is just a quick and simple solution and not the ideal solution to solve the problem of full screen without the image being compressed or stretched.
thanks @Nocturne đź‘Ť
 
Use a view camera and set it to the room width then scale the height to the device. So, on game start you get the size of the display, then activate the view[0] and set the port width and height to the DISPLAY size, then you set the camera width to the width you want (480), and set the camera height to the relative height of the display based on the display aspect ratio (you get the aspect ration by doing display width/height, then get the camera height by doing 480/ratio).
Ok, so I tried breaking everything above into steps. Is this a correct order of things? Did I miss or misunderstand something?

1. Use a view camera
2. set it to the room width
3. scale the height to the device.
4. activate the view[0].
5. set the port width and height to the DISPLAY size.
6. set the camera width to the width you want (480).
7. set the camera height to the relative height of the display based on the display aspect ratio (you get the aspect ration by doing display width/height, then get the camera height by doing 480/ratio).
 
Top