GMS 2 Scaling GUI object placement

Discussion in 'Programming' started by Erayd, Jan 3, 2019.

  1. Erayd

    Erayd Member

    Joined:
    Jun 23, 2016
    Posts:
    135
    I have a theory I'm wondering if anyone passing by here can confirm or not.

    My gui layer is set to the resolution of the player's monitor so as to have the highest resolution for certain graphics. Before I built that function in, I had been setting all my element's locations by static values like x= 50, y = 120. The obvious problem with that is that after resizing the gui layer, 50 x 120 is no longer where I wanted it to be, so my whole gui was still visually the same size.

    One answer is to have different resolution options the player can choose and then adapt the gui based on that choice, however, I'm wondering if I can instead just use ratio values to place all of my objects on the gui layer?

    Example: (where gui_width is recorded when the gui layer changes, in this case, display_get_gui_width())
    Code:
        var picked_x = gui_width/15;
        var picked_y = gui_height - picked_item_back_height - gui_height/10;
        
        //Background
        draw_sprite_ext(picked_item_back, -1, picked_x, picked_y, 1, 1, 0, c_white, picked_item_a);
    I don't have a bunch of monitors to test this on, plus its still just a theory. If nobody has any ideas then I could just adjust the gui size to several different common monitor sizes and see what happens. Just throwing it out there for now. My hope is that by using ratios, the sprite objects always render in the same location since the game view will be the size of the display but a small scale resolution and the gui layer will also be the same size as the display, but a much higher resolution.
     
  2. dialgpalkia

    dialgpalkia Member

    Joined:
    Jan 2, 2019
    Posts:
    57
    It sounds like a good idea but you’d need to be able to determine the monitor in uses’ resolution. Say for example your game runs mainly on a 640x480 view. You have a monitor that has resolution 1900x1280 for example, if you could detect that manually, you could just scale the placements of all objects by a factor of (1900/640)x(1280/480).
     
  3. Erayd

    Erayd Member

    Joined:
    Jun 23, 2016
    Posts:
    135
    display_get_width() and display_get_height() would be that detection your talking about. That gets the monitor resolution width and height.
     
  4. dialgpalkia

    dialgpalkia Member

    Joined:
    Jan 2, 2019
    Posts:
    57
    That’s right, it’s been a while since I used them.
    If you get that and multiply by the ratios it would work, at least theoretically. You’d have to do some testing though.
     

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