GMS 2 [SOLVED] Resizing view to prevent black bars (on mobile devices)

D

Doug

Guest
SOLVED:
Post #2 has links to tutorials
Post #5 has amendments to tutorial to make it work


Hi everyone,

I'm struggling with a process that someone may be able to help with. I've followed many tutorials, looked at many forums, but unfortunately I've been unable to find what I'm looking for.

I'm creating a game for Android. My current phones to test it on are a Galaxy S6, Moto E and Moto G 2nd Gen. All of these phones have the same aspect ratio, 16:9, and I wish for my game to work on tablets with 4:3 ratio without black bars (well any other ratio really!). The view is currently 1024w 576h, and the rooms are much larger than the view.

I believe I understand that the best way of doing something like this is to:
  • Lock one of the views (say, lock the 1024 width, as the game depends on a specific width to be maintained), then change the height according to the new aspect ratio i.e. change the original 576 (16:9) to 768 (4:3), without stretching (just view more of the room instead, preventing black bars at the top and bottom).

Annoyingly, I cannot for the life of me work out how to do this! Is someone able to help, please?

Thank you very much in advance!
 
Last edited by a moderator:
D

Doug

Guest
Thanks chamaeleon.

I found Pixelated Pope's guide earlier and tried to work from that. It wasn't working for so long, but when I deleted:

Code:
if (display_height mod ideal_height != 0)
{
    var d = round(display_height/ideal_height);
    ideal_height=display_height/d;
}
if (display_width mod ideal_width != 0)
{
    var d = round(display_width/ideal_width);
    ideal_width=display_width/d;
}
It started working as intended, and extends the view/camera's height for all aspect ratios (and keeps the width as it is). Just for the record, the most popular aspect ratios among android devices are:

Code:
4:3
3:2
8:5
5:3
16:9
Thanks a lot, I'll marked the post as solved.
 
I found Pixelated Pope's guide earlier and tried to work from that. It wasn't working for so long, but when I deleted:

Code:
if (display_height mod ideal_height != 0)
{
var d = round(display_height/ideal_height);
ideal_height=display_height/d;
}
if (display_width mod ideal_width != 0)
{
var d = round(display_width/ideal_width);
ideal_width=display_width/d;
}
It started working as intended, and extends the view/camera's height for all aspect ratios (and keeps the width as it is).
Not sure what you mean by "wasn't working" but that part of the code is the "perfect scaling" code which changes your ideal width and height to be a factor of the display's width and height. Glad you got it working, though.
 
Top