GMS 2 Allowing multiple aspect ratios without stretching display

W

Wreathesent

Guest
hi
I've been stuck on this one problem for about too long now: adjusting the resolution without stretching/scaling the game.
I'm using a view that follows the player and when the aspect ratio is changed i want the view size to change, leaving the GUI and object/sprite sizes the same.

Like let's say the game defaults to 4:3 -


But the user wants to play it in 16:9. it should look like this -


But despite trying several solutions, trying solutions made by other users, following tutorials (that aren't videos), i keep getting this when switching to 16:9 -



I'm absolutely stuck on this, as I won't be able to work on basically anything else without resolving this first.
---

Also, I hope this isn't too unrelated for this topic/thread but is there a way to keep interactive objects in the same place regardless of the view position? (like the inventory thing on the right)

Your help is greatly appreciated, thank you so much <3
 

RangerX

Member
Unless you have code that might interfere with this, Gamemaker can do this automatically for you.
Its the "keep aspect ratio" option in the graphic tab of your target's global settings.
 

Alv

Member
You have to resize at runtime all the views in the game. I modified an old script for this purpose:
Code:
// argument0...aspect ratio
// argument1...screen width

var hres,vres;
hres=argument1;
vres=argument1/argument0;

for (i=0;i<1000;i+=1) {
    if (room_exists(i)) {
        room_set_view_enabled(i,true);
        room_set_view(i,0,true,0,0,hres,vres,0,0,
        hres,vres,32,32,-1,-1,noone);
    }
}

surface_resize(application_surface, hres, vres);
if (!window_get_fullscreen())
   window_resize_center(hres,vres);
Here is the window_resize_center script:
Code:
var xcenter,ycenter;
xcenter=window_get_x()+window_get_width()/2;
ycenter=window_get_y()+window_get_height()/2;
window_set_rectangle(xcenter-argument0/2,ycenter-argument1/2,argument0,argument1);
Remember that, in this way, the view height can change. So you have to use view_yview[0] and view_hview[0] to anchor to the view the GUI objects...
 
Last edited:
W

Wreathesent

Guest
Unless you have code that might interfere with this, Gamemaker can do this automatically for you.
Its the "keep aspect ratio" option in the graphic tab of your target's global settings.
I have that enabled, actually! But it's not what solves the problem here. I use that for scaling/fullscreen but after the aspect ratio is changed.

You have to resize at runtime all the views in the game. I modified an old script for this purpose:
Code:
// argument0...aspect ratio
// argument1...screen width

var hres,vres;
hres=argument1;
vres=argument1/argument0;

for (i=0;i<1000;i+=1) {
    if (room_exists(i)) {
        room_set_view_enabled(i,true);
        room_set_view(i,0,true,0,0,hres,vres,0,0,
        hres,vres,32,32,-1,-1,noone);
    }
}

surface_resize(application_surface, hres, vres);
if (!window_get_fullscreen())
   window_resize_center(hres,vres);
Here is the window_resize_center script:
Code:
var xcenter,ycenter;
xcenter=window_get_x()+window_get_width()/2;
ycenter=window_get_y()+window_get_height()/2;
window_set_rectangle(xcenter-argument0/2,ycenter-argument1/2,argument0,argument1);
Remember that, in this way, the view height can change. So you have to use view_yview[0] and view_hview[0] to anchor to the view the GUI objects...
room_set_view and view_xview/yview aren't supported in gms2. Apparently cameras are supposed to replace those. I made a new script that worked, lightly based on this one , GUI moves when needed (mainly the text boxes/menus) because the x and y are relative to the camera width/height. But in fullscreen those variables do not change and the GUI sprites and text are drawn in the top left corner. I can't use window_get_height/width because they would be drawn offscreen in fullscreen mode.
Code:
ratio = argument0;
scale = argument1;
aa      = argument2;
vsync = argument3;
fullsc= argument4;


rwidth  = string_copy(ratio,0,string_pos(":",ratio)-1); //16
rheight = string_copy(ratio,string_pos(":",ratio)+1,string_length(ratio)); //9

//minimum scale/default
scale_min = 640/real(rwidth);
width = real(rwidth) * scale_min;
height = real(rheight) * scale_min;

//scaling
if scale < 1{
    scale = 1
    }
swidth = width * scale;
sheight = height * scale;

camera_set_view_size(view_camera[0], swidth, sheight);
window_set_size(swidth,sheight)
But aside from that I think this problem is solved, just need to put views in every room
I feel like this reply is unrelated but I didn't want to not respond to this also thanks for the help
 
Top