1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Allowing multiple aspect ratios without stretching display

Discussion in 'Programming' started by Wreathesent, Jul 14, 2018.

  1. Wreathesent

    Wreathesent Member

    Nov 22, 2017
    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
  2. RangerX

    RangerX Member

    Jun 20, 2016
    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.
  3. Alv

    Alv Member

    Jun 27, 2016
    You have to resize at runtime all the views in the game. I modified an old script for this purpose:
    // argument0...aspect ratio
    // argument1...screen width
    var hres,vres;
    for (i=0;i<1000;i+=1) {
        if (room_exists(i)) {
    surface_resize(application_surface, hres, vres);
    if (!window_get_fullscreen())
    Here is the window_resize_center script:
    var xcenter,ycenter;
    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: Jul 14, 2018
  4. Wreathesent

    Wreathesent Member

    Nov 22, 2017
    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.

    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.
    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;
    if scale < 1{
        scale = 1
    swidth = width * scale;
    sheight = height * scale;
    camera_set_view_size(view_camera[0], 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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice