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 [SOLVED] Scaling the GUI correctly to different screen sizes

Discussion in 'Programming' started by Spencer S, May 4, 2018.

  1. Spencer S

    Spencer S Guest

    Everything below works for my screen, including the GUI functions (my screen is 2736x1824).

    Room Creation Code:
    Code:
    view_visible[0] = true;
    view_enabled = true;
    
    // Variable used to change gui ratio and/or gui aspect ratio. if this is changed, this same variable needs to be changed in the Create event in obj_equipped_inventory_gui as well.
    guiAspectScaling = 0.1;
    
    camera = camera_create_view(0, 0, 20480, 15360, 0, obj_player, -1, -1, 10240, 7680);
    var viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0);
    var projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0);
    camera_set_view_mat(camera, viewmat);
    camera_set_proj_mat(camera, projmat);
    
    view_set_camera(0, camera);
    
    display_set_gui_size(display_get_width(), display_get_height());
    display_set_gui_maximise(guiAspectScaling, guiAspectScaling, 0, 0);
    
    Just as an FYI, I use the guiAspectScaling to convert into a multiplier called guiScalingVector which is then multiplied against all object positions and sizes. For example, instead of drawing a sprite on the GUI later to (display_get_width() / 2), I draw the sprite to ((display_get_width() / 2) * guiScalingVector), which then correctly puts the drawing in the middle of the screen.

    The problem is that when I run my game on any other monitor with a different resolution, the game itself is still drawn fine, but the GUI is drawn incorrectly. Basically, its just the display_set_gui_size() and display_set_gui_maximise() functions that are giving me a problem. I've tried messing with resolution ratios, and I've watched Pixelated Pope's youtube tutorials on cameras, as well as Shaun Spalding, but I can't seem to get it down.

    What I need is some way to get the aspect ratio and correctly change the GUI so that everything still draws correctly.
     
  2. bilouw

    bilouw Member

    Joined:
    Dec 25, 2017
    Posts:
    32
    I'm currently making my GUI with theses tutorials too! What is the problem with you GUI? Are you sure that the GUI size is always at the same size of your resolution screen? Also, Do you use image in your GUI? If yes, you need to resize these image in fonction of the GUI resolution, and all the assets need to be draw dynamically in fonction of your screen width/height.

    Edit : Why are you using display_set_gui_size et after, display_set_gui_maximise? You should only use one of them.
     
  3. Spencer S

    Spencer S Guest

    Ahhhh, that was my issue. I was trying to use display_gui_set_size, but display_set_gui_maximise was screwing me up. Removing the second function worked just as intended.
     

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