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
  2. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 How to change resolutions without pixel distortion?

Discussion in 'Programming' started by alex19735, Oct 20, 2019.

  1. alex19735

    alex19735 Member

    Joined:
    Dec 28, 2018
    Posts:
    6
    Hi, I am writing to ask about something I've been battling for a while. I want my game to use the resolution of the player's screen, but also remain the same scale. I don't want the game to look more zoomed out on larger resolutions. I do this by setting the camera's view size to the base resolution of my game (1280 by 720). This works well, however when scaling to, say, 1920x1080, the pixels get distorted, because 1920x1080 divided by 1280x720 is 1.5. How can I scale the game view to match the device's resolution, without getting pixel distortion?

    Code:
    view_wport[0] = displayWidth;
        view_hport[0] = displayHeight;
        
        if (view_get_wport(0) != displayWidth){
            view_set_wport(0, baseWidth);
            view_set_hport(0, baseHeight);
            camera_set_view_size(view_camera[0], baseWidth, baseHeight);
        }
        if (surface_get_height(application_surface)!=displayHeight){
            surface_resize(application_surface, displayWidth, displayHeight);
        }
    This is the game in windowed mode, where there is no scaling:
    game_normal.png

    And here it is in fullscreen, scaled to 1920x1080:
    game_distorted.png

    I've noticed that the GUI Layer does not suffer from this problem, and it scales perfectly! So surely there must be a way to scale 1280x720 to 1920x1080 without any pixel distortion?

    Thank you in advance, and sorry if I explained things badly, I don't really know how to word this any better.
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,273
    I recommend the following tutorials as a good starting point to understanding and managing your games resolution.

    How to properly scale your game!


    Scaling, Resolution, and Aspect Ratio Management for GMS1 & GMS2


    Basically if you want to scale a pixel perfect game without distortion, you must scale your resolution by an integer factor, e.g. 1,2,3,4...etc...

    If your games resolution doesn't fit neatly into the devices resolution, as in your example of 1280x720 not fitting in to 1920x1080, you need to scale it up to the nearest best fit integer multiple and have black bars or other graphics filling the borders.

    But the above links will explain it much better than I have tried to do briefly here.
     
  3. alex19735

    alex19735 Member

    Joined:
    Dec 28, 2018
    Posts:
    6
    That really is a bummer. I have read those guides before and I understand why this happens, it's just really frustrating because I obviously want to make it look as good as possible on any device configuration.

    Is there any way to scale the actual game contents without scaling the view? Like scaling the game objects or something like that. If not, I guess I will have to compromise and use black bars.

    Thank you in advance!
     
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,981
    Well if you understand why it happens, then you should also realize that full, smooth scaling of any random room size is not possible, because pixels. Best you can do is to mitigate the effects. Choose a low resolution for your view which has the most common display res (1920x1080) as its integer multiplier result, for example 480x270 (x4) or 640x360 (x3). Large scaling means on displays not of integer scale factor the added pixel stretch is not easily noticeable. Or calculate the largest integer multiplied size that fits display and scale with that, leaving black borders all around. Maintain aspect ratio so there's no additional stretching, which means on displays not of 16:9 aspect you add black bars.

    EDIT or do a combination of integer scaling and adjusted view size. That is, calculate the largest integer scale multiplier and then adjust view size to fill the screen. I recall Sunless Sea does this, at least I seem to remember when you use different display resolutions, the distance how far around your ship you can see changes (meaning playing at certain display resolutions offers a view distance advantage).
     
    Last edited: Oct 22, 2019
  5. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,596
    Today you learned that a game that looks good is a game with no distorted graphics. Sorry you can't have both full scale and no distortion but if ever you want a relief, no games ever in the history of making games did that because its a purely logic limitation of pixels based screens. And no game ever in the futur of forever into infinity will do it for as long as its displayed in a pixel based screen. :)
     

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