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

Discussion in 'Tutorials' started by Pixelated_Pope, Sep 12, 2016.

  1. Bence Monori

    Bence Monori Member

    Joined:
    Jul 2, 2018
    Posts:
    2
    .
     
    Last edited: Jul 25, 2018
  2. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    Great tutorial! I am having one issue though. For some reason it is drawing a black bar at the top of screen, but doesn't do it if I comment out the pixel perfect portion of the script.

    I'm using the GMS 2 version of the tutorial, have checked the code multiple times, but can't seem to figure out what might be causing it. My ideal height is set to 540 with my room sizes at 960x540.
     
  3. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @IndieRex
    I don't recommend using the pixel perfect scaling... but that said, it certainly shouldn't give you black bars. What's the resolution of your monitor?
     
  4. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    1920x1200. There is only one bar at the top of the screen (rather than one at bottom and top). Not sure why turning it off is fixing it either.

    I'll keep it turned off then!
     
  5. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @IndieRex

    Ah, because your room isn't tall enough! When you scale it to be pixel perfect, it will scale the height to be perfect. 540 doesn't go perfectly into 1200, so it resizes your view to be 600 tall. Your rooms are only 540 tall, so you see the outside of your room, which is black.
     
    IndieRex likes this.
  6. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    Ah that makes sense! Thanks again for your help. Great series - really appreciated the lead-up videos explaining the background of the topic and laying the groundwork for the system.
     
    Pixelated_Pope likes this.
  7. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    Sorry for another question so soon, but I'm now having an issue where the text I draw is getting distorted (I think only in fullscreen mode). I did a check and my camera width/height are running at 864x540.

    My rooms are 960x540, my ideal height is set to 540, and my computer resolution is 1920x1200.
     
  8. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Are you drawing your text in a gui event? When you are in full screen, do you have black bars at the top and bottom (you shouldn't)?
     
  9. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    No black bars. Seems to be an issue in both Draw and Draw GUI events.
     
  10. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @IndieRex
    So, the only time there should ever be distortion is when aspect ratios don't match. Specifically your view and your application surface. Here's a script I use to debug all this.

    https://www.dropbox.com/s/tupyzjlwk9fz7sr/display_write_specs_GMS2.gml?dl=0
    https://www.dropbox.com/s/wnvl0ok047w1d95/display_write_all_specs_GMS2.gml?dl=0

    Add those two scripts to your project, and then in your draw_gui event somewhere write:
    Code:
    display_write_all_specs_GMS2(5,5);
    The numbers in the parentheses is your aspect ratio for that element. All of those numbers should be the same. If not, there's a chance for distortion. So that should give you an idea where to look. If you still can't figure it out, send me a screenshot, and I'll be happy to help you.

    Also, just FYI, you can join my Discord server where hundreds of awesome GM developers hang out and help each other. It's a great way to get programming help without the waiting for forum post responses, and I'm there 5 days a week along with many very skilled and helpful developers. https://discord.gg/sehNsp
     
  11. IndieRex

    IndieRex Member

    Joined:
    Aug 7, 2018
    Posts:
    8
    @Pixelated_Pope

    Thank you for the scripts. I ran it, but it looks like they are all the same number. Here is a screenshot showing it. The issue is also definitely not the font either as when I run the game without the scaling system it looks great. I'm on the discord as well too!
     

    Attached Files:

  12. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @IndieRex That is indeed weird. The only thing I can really think of is that there is some sort of pixel interpolation going on. Do you have that setting turned on? Even then, it looks weird. If you'd be willing, you could PM me your project and I'll see if I can figure out what's going on.
     
  13. TylerMcDe

    TylerMcDe Member

    Joined:
    Jun 30, 2018
    Posts:
    11
    This tutorial is the gift that keeps on giving for years now lol.
     
  14. rouzbeh78

    rouzbeh78 Member

    Joined:
    Aug 19, 2018
    Posts:
    2
    Hi
    I saw all videos and do whatever you said
    my orginal view must be like this :
    [​IMG]
    but in my phone i get this result:

    [​IMG]

    why is that ??
    this is my obj_display_manager:
    CREATE:

    ideal_width=0;
    ideal_height=720;
    zoom=1;
    max_zooom=1;
    display_width=display_get_width();
    display_height=display_get_height();

    aspect_ratio=display_width/display_height;
    //aspect_ratio=clamp(aspect_ratio, 1280/720, 1280/720);

    ideal_width=round(ideal_height*aspect_ratio);
    //ideal_height=round(ideal_width / aspect_ratio);

    //Perfect Pixel Scaling
    if(display_width mod ideal_width != 0)
    {
    var d = round(display_width/ideal_width);
    ideal_width=display_width/d;
    }
    if(display_height mod ideal_height != 0)
    {
    var d = round(display_height/ideal_height);
    ideal_height=display_height/d;
    }

    //Check for odd numbers
    if(ideal_width & 1)
    ideal_width++;
    if(ideal_height & 1)
    ideal_height++;

    //Calculate Max Zoom
    max_zoom=floor(display_width/ideal_width);

    for(var i=1; i<=room_last; i++)
    {
    if(room_exists(i))
    {
    room_set_view(i,0,true,0,0,ideal_width,ideal_height,0,0,ideal_width,ideal_height,0,0,0,0,-1);
    room_set_view_enabled(i,true);
    }
    }


    window_set_size(ideal_width,ideal_height);
    display_set_gui_size(ideal_width,ideal_height);
    surface_resize(application_surface,ideal_width*zoom,ideal_height*zoom);

    alarm[0]=1;

    room_goto_next();

    ALARM[0]

    window_center();

    unfortunately i used 1280x720 but I do not think this have anything to do with my problem
    i also used GMS2 and saw Part 5 of your videos series but that couldn't help to
    and also i don't need any view to follow my characters.
    please somebody help me :(
     
    Last edited by a moderator: Aug 19, 2018
  15. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @rouzbeh78 Okay. First off, it looks like your game isn't pixel art based, so 720p is just fine :D.

    So, remove the pixel perfect scaling portion of the code:
    Code:
    //Perfect Pixel Scaling
    if(display_width mod ideal_width != 0)
    {
    var d = round(display_width/ideal_width);
    ideal_width=display_width/d;
    }
    if(display_height mod ideal_height != 0)
    {
    var d = round(display_height/ideal_height);
    ideal_height=display_height/d;
    }
    Remove all that. That alone may fix it for you depending on the resolution of your phone.

    As for view following your characters, I discuss how to do that in my Part 5 video.
    camera_view_set_pos(view_camera[0],player.x,player.y)
     
  16. rouzbeh78

    rouzbeh78 Member

    Joined:
    Aug 19, 2018
    Posts:
    2
    thank you so much that does the trick ! :)
     
  17. w0rm

    w0rm Member

    Joined:
    Aug 20, 2016
    Posts:
    12
    Thanks for the great tutorial @Pixelated_Pope!!

    The code works great also in GMS2. I wanted to separate the camera controlling code from the display manager object to its own. For a moment I had hard time playing with those global variables etc. Then by browsing docs I found a way to get completely rid of those by making the changes shown below. I decided to share this in case it's helping someone working with your great code.

    Create event:

    Replace

    Code:
    camera = camera_create();
    globalvar view_x,view_y,view_w,view_h;
    view_x = 0;
    view_y = 0;
    view_w = ideal_width;
    view_h = ideal_height;
    with

    Code:
    camera = camera_create_view(0, 0, ideal_width, ideal_height, 0, -1, -1, -1, 0, 0);
    This allows using those new camera and view related functions which camera_create() apparently does not. Also setting of the view size in the End Step event is not necessary anymore. NOTE! The code used to show display specs needs updating as well...

    After that it's easy to move and update the view positioning code from the End Step event to another object as below.

    End Step event:

    Replace with

    Code:
    var _view_w = camera_get_view_width(view_camera[0]);
    var _view_h = camera_get_view_height(view_camera[0]);
    var _view_x = instance_followed.x - _view_w / 2;
    var _view_y = instance_followed.y - _view_h / 2;
    
    var _round = _view_w / surface_get_width( application_surface );
    camera_set_view_pos(view_camera[0], round_n( _view_x, _round ), round_n( _view_y, _round ) );
    
    Of course one needs to set the instance to be followed in the Create event of this (or use object reference as in the original).
     
  18. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Ah, good adjustments, @w0rm!

    At the time I was writing the tutorial, I believe camera_create_view was bugged and not working as expected, which is why I didn't use it at the time. Thanks for patching the tutorial for me :D
     
    kupo15 likes this.
  19. instaboy

    instaboy Member

    Joined:
    Sep 23, 2018
    Posts:
    7
    Hi. Did you find a solution? Thanks!
     
  20. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @instaboy Chances are the view was using the "object following" feature while also using an increased application surface size, which many people use without even realizing it. This causes jittering. Best thing to do is move to a manual camera control, and maybe add some smoothing as well.
     
  21. instaboy

    instaboy Member

    Joined:
    Sep 23, 2018
    Posts:
    7
    Thanks for the quick answer! I already use manual camera control (tried different versions). The main problem is that the player moves very smooth but other objects/characters are very blurry/jitter/ghosting?. Especially when the player (and the camera) move in the opposite direction than the other objects. It occurs more on higher move speeds, like 2px per step (640*360 base res.). This is really a show stopper. What do you mean by "add some smoothing as well."? Thanks in advance!
     
  22. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Ah, okay. So, try this. Can you capture the issue in a screenshot? If not, this is likely an art issue. Obviously I've not seen your game, but I'm guessing it is fairly early and using a lot of placeholder art, with bright colors. When things with bright colors move quickly on an LCD monitor, you are more likely to get "ghosting" and other strange looking things. This is not an issue with your code, but with your art. It happens in almost all 2D games with fast motion, but you don't notice it because there are more interesting things to be paying attention to. So ultimately, your only solution is to ignore it until it goes away as your game gets more content and better art.

    If you don't believe that is the issue, you could send me a build of your game and I could see if I can reproduce the issue on my machine and offer some further insight.
     
    instaboy likes this.
  23. instaboy

    instaboy Member

    Joined:
    Sep 23, 2018
    Posts:
    7
    Thanks a lot for you help! You were 100% right :)
     
  24. Rekenq

    Rekenq Member

    Joined:
    Sep 26, 2018
    Posts:
    11
    @Pixelated_Pope I saw your tutorials, they're amazing, thanks for sharing all that! I was wondering if there's anyway to keep the quality of sprites when down scaling instead, or should I never down scale at all?
     
  25. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @Rekenq By down scaling, you mean displaying a larger view in a smaller application surface?
     
  26. Rekenq

    Rekenq Member

    Joined:
    Sep 26, 2018
    Posts:
    11
    Yes. I'm using this code on a project

    Code:
    if(os_type == os_android)
    {
       window_set_size(464,261);
       window_center();
       surface_resize(application_surface,464,261);
    }
    
    It is an HTML project that needs to run on both PC and Mobiles. The viewport size is 928x522 (the same as the camera's), which is the max 16:9 resolution we could fit on the page. But this resolution is too big for some mobile devices so we resize the window and surface to half that. The problem is that the animated sprites lose a lot of quality, they show a lot of visual artifacts and aliasing. Should I be doing the opposite? Designing on 464x261 and then up scaling like in your video?
     
  27. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Oh, yeah. If you are scaling down pixel art, that's going to look awful. If it's not pixel art, you could just turn on interpolation, and it would look pretty great.
     
    Rekenq likes this.
  28. Rekenq

    Rekenq Member

    Joined:
    Sep 26, 2018
    Posts:
    11
    Alright, I'll give that a try! Thank you very much for your help!
     
  29. Vallo92

    Vallo92 Member

    Joined:
    Jun 20, 2016
    Posts:
    63
    Hello @Pixelated_Pope ,
    I've seen all your videos on this subject, but unfortunately I'm new enough in GM and I'm having trouble getting your codes working properly in my project, so I'd like to ask you if you can help me.
    My project is entirely in pixel art, so I have to make sure that the pixels are correctly scaled, to avoid sprites malformation. The game must be played on a mobile in a vertical position (portrait).
    I use a 360x640 room. Here is a sample image of my current room:
    example1.png
    As you can see inside the room there is a box. I would like that box to always be in that position in whatever resolution is displayed. In short, I need the objects in the room to always be displayed at the usual locations.
    So I thought to always keep the usual vertical height, and act on the horizontal background, to match the aspect ratio of the screen of the mobile device (I would like to avoid having black bars in the game).
    Following your videos I realized that I could use a wider background, so as to display it if the resolution is greater than 360x640. Here is an example image epr better understand what I mean:
    example2.png

    Is this method correct?
    To make this method work I have to use the views inside GM (I'm not currently using it, and I have placed all my objects based on the room's coordinates).

    At the code level, how should I proceed to have a correct size port without black bars, and still have a correct pixel art display?

    Thank you so much in advance!
     
    Last edited: Feb 28, 2019
  30. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Looks like you are on the right path! You need to use views to properly manage your resolution in most cases. Another option is to disable the automatic drawing of the application surface and draw your app surface manually in the GUI event. Then you can maximize the GUI and draw any image you want in the background while drawing your app surface scaled up as much as possible and perfectly centered.
     
    Vallo92 likes this.
  31. Vallo92

    Vallo92 Member

    Joined:
    Jun 20, 2016
    Posts:
    63
    I did a test on my pc with this code (not tested on mobile devices). In your opinion could you go using the view option? As for perfect pixel art scaling, should I have problems?
    If I start a test with this code, a window of 720 (h) x1280 (w) is created.
    Code:
    ideal_width=360;
    ideal_height=640;
     
    //Aspect ratio
    aspect_ratio = display_get_width()/display_get_height();
     
    //Calculate new ideal width.
    ideal_width=round(ideal_height*aspect_ratio);
    ideal_height=round(ideal_width/aspect_ratio);
     
    ideal_width=round(ideal_width);
    ideal_height=round(ideal_height);
     
    if (display_get_width() mod ideal_width != 0) {
        var d = round(display_get_width()/ideal_width);
        ideal_width = display_get_width()/d;
    }
    if (display_get_height() mod ideal_height != 0) {
        var d = round(display_get_height()/ideal_height);
        ideal_height = display_get_height()/d;
    }
    
    if(ideal_width & 1)
      ideal_width++;
     
    if(ideal_height & 1)
      ideal_height++;
     
     
     
    //Setup all the view ports so I don't have to.
    globalvar Main_Camera;
    Main_Camera = camera_create_view(0,0,ideal_width,ideal_height,0,noone,0,0,0,0);
    camera_set_view_size(Main_Camera,ideal_width,ideal_height);
     
    for(var i=1; i<= room_last; i++)
    {
      if(room_exists(i))
      {
            room_set_view_enabled(i,true);
            room_set_viewport(i,0,true,0,0,ideal_width,ideal_height);
            room_set_camera(i,0,Main_Camera);
      }
    }
     
    surface_resize(application_surface,ideal_width,ideal_height);
    display_set_gui_size(ideal_width,ideal_height);
    window_set_size(ideal_width,ideal_height);
    room_goto_next();
    Also I wanted to ask you if I can leave my room size at 360x640 and simply insert a larger background, or if I have to enlarge the room completely, so that if the view has to be enlarged the room has free space for it.
     
    Last edited: Feb 28, 2019
  32. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @Vallo92
    Are you on GMS2? If so, you might want to check out my latest tutorial to simplify this a bit. You don't need to create "cameras" or use that for loop to set up the views.
    As for your code, I don't see anything immediately wrong with it. you can definitely roll with just using the dynamically sized view.

    And, as far as I know, the only thing 'room size' really matters for is when you are using tiles. Other than that, your room can be literally any size.
     
  33. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    quick question what if i want to keep black bars on left and right of screen ? i'm trying to get my view of 320x240 to scale to my 1080p monitor without pixel distortion (i'm using gms2)
     
    Last edited: Apr 12, 2019
  34. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @BitmapSkies
    GMS1 or GMS2? Also, I recommend joining my discord server (link in my sig) and we can talk about this in real time. Much easier to debug that way.
     
  35. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    gms2 i dont use discord wants you to faff about signing up,
    its just an extremely basic 2d platformer the pixel art view everything in 320x240 and distorts at full screen on my 1080p monitor i want to keep the none widescreen with the borders on the sides
     
  36. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Okay, so since you are on a more square aspect ratio, it's going to stretch your height out to fill the vertical space. So 1080 / 240 = 4.5. That .5 is the cause of any distortion you see. So your only real option is to manually draw the app surface so that it doesn't stretch to fill the whole window. This will result in a "black box" rather than black bars all around your game. But all pixel distortion will be eliminated as you'll be perfectly scaling to 4x instead of 4.5x
     
  37. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    ah yes i see cause im asking for the extra height ? hmm now i understand why scaling in none intergers is bad , ok then so gms2 wont work with none widescreen ? how do i stretch the height , keeping black borders on the side without being in a box ? i dont get this considering gms2 is supposed to be mostly for pixel art ? the old gm didnt have this problem dont tell me im going to have to redo all my pixel art for the sake of a few pixels ? its so annoying .
    ps : so what should i be using for the pixel art as close to 320x240 to get it to scale without making the game widescreen ? what if it get played on a none exact 1080 screen ? (16 bit platformer)
     
  38. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    ps : all this has just reminded me why i stopped making games after gm8
     
  39. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    @BitmapSkies
    This has nothing to do with GameMaker. This is just how graphics work. You have a monitor with a set number of pixels, you have an image with a set number of pixels. If you try to scale the image to fit the monitor, and you have to scale with non-whole numbers, then some pixels are going to be smaller than other pixels. Your monitor is made up of physical pixels, and there's nothing you can do about that. Unless you want to use some fancy shaders to try and smooth out your scaling, you will have pixel distortion. That said, in my experience, depending on the art style, scaling up to anything over 3x usually doesn't look that bad. For example, take this screenshot from Seiken Densetsu 3
    [​IMG]
    it's native resolution is 256x224. But that up there is scaled up to fit a 1080p monitor (if you view the image in full screen.) That's a scale of 4.821428...x Can you spot the pixel distortion? Even if you could pick it out in a static screenshot, I'd bet you'd have a hard time noticing it when actually playing the game. But it is definitely there.

    [​IMG]

    Most people play emulated SNES games at 1080p on their PCs, and very few complain about this sort of distortion; not because it isn't present, but because it isn't noticeable at this scale.

    So if you are seeing really serious distortion at your chosen resolution when scaled to 1080, I would first make sure you are scaling correctly and there isn't anything else at play. And then I'd examine your art style... maybe it's making distortion more obvious? I'd have to see a screenshot of your issues to know for sure.
     
    mamacato likes this.
  40. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    yeah i went away calmed down and had a nice brain squeltch, you've basicaly just replied what i was thinking of haha, yeah i'll be honest i'm a big emulator guy so i should know about all this , mabye i got confused by digesting 1000s of hours of pixel art lectures and the beauty of 240pixels of platformer specialisation (since making platformers in widescreen is .... silly unless you design your levels with widescreen in mind , i am however still dumbfounded as to why gamemaker doesnt just add the extra pixels into the borders on the side(how i would like) so doing a little calulator ive worked out the levels need to be made with 480 x 270 in mind ? i am also thinking , that mabye i never noticed the distortion back in 2008 cause i was on a 4:3 crt monitor , i just ran my stone age 2008 gm8 game on my 1080 and yes pixel distortion soooooo ...... looks like im going to be forced to make my levels in widescreen meh .
     
  41. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    That's not necessarily true either. Your desired aspect ratio is 4:3 (1.3333). So if you pick a desired height that is a whole number factor of 1080 (so either 270 or 216) and then calculate the width based on the desired aspect ratio (1.333) you get two possible, non full screen resolutions that will scale perfectly to 1080p with black bars on the sides: 280 x 216 or 360 x 270. Design your game around either of those resolutions, and you'll scale well on 1920x1080 monitors.
     
    BitmapSkies likes this.
  42. BitmapSkies

    BitmapSkies Member

    Joined:
    May 25, 2017
    Posts:
    9
    Thank you so much pope , 280 x 216 was the golden number for my 8 bit games and 360 x 270 for my 16 bit games , you just fixed everything yippeeee !!!! :D
    ps: ill have to redo a little pixel art for menus and such but my sprite work is unharmed and now in perfect square pixel but blown up on 1080, also my brother has a 4k screen i wonder what it will look like on his screen hehe thank you again :)
     
  43. Vallo92

    Vallo92 Member

    Joined:
    Jun 20, 2016
    Posts:
    63
    Hello,
    I'm sorry if I disturb you but I'm having trouble getting your codes to work properly. Here is my current code (I use the last version of GM2):
    CREATE:
    Code:
    ///Properties
    ideal_width=0; //Doesn't matter because we are going to calculate this.
    ideal_height=640;
    display_width=display_get_width();
    display_height=display_get_height();
    
    //Aspect ratio
    aspect_ratio = display_width/display_height;
    
    //Calculate new ideal width or height
    ideal_width=round(ideal_height*aspect_ratio);
    //ideal_height=round(ideal_width/aspect_ratio);
    
    ideal_width=round(ideal_width);
    ideal_height=round(ideal_height);
    
    //Perfect Pixel Scaling
    if(display_width mod ideal_width != 0)
    {
      var d = round(display_width/ideal_width);
      ideal_width=display_width/d;
    }
    if(display_height mod ideal_height != 0)
    {
      var d = round(display_height/ideal_height);
      ideal_height=display_height/d;
    }
    
    //Check to make sure our ideal width and height isn't an odd number, as that's usually not good.
    if (ideal_width & 1) {
        ideal_width++;    
    }
    /*if(ideal_height & 1)
      ideal_height++;*/
    
    surface_resize(application_surface,ideal_width,ideal_height);
    display_set_gui_size(ideal_width,ideal_height);
    window_set_size(ideal_width,ideal_height);
    
    alarm[0] = 1; // Centra window puoi rimuovere
    camera = camera_create();
    
    room_goto(rInizializzazione);
    END STEP:
    Code:
    camera_set_view_size(view_camera[0], ideal_width, ideal_height);
    camera_set_view_pos(view_camera[0], room_width/2-camera_get_view_width(view_camera[0])/2, room_height/2-camera_get_view_height(view_camera[0])/2);
    
    ROOM START:
    Code:
    view_camera[0]=camera;
    view_enabled=true;
    view_visible[0]=true;
    ROOM END:
    Code:
    view_camera[0]=noone;
    This is a result:
    exaple.jpg

    My game room has dimensions 360x640 (horizontal orientation), and the background I use is 360x640. In the code I inserted an "ideal_height" of 640, just because I would like to keep the original height, and only modify the width to fix the aspect ratio.
    The problem is that the height of the window is also changed and the resolution no longer has a height of 640 as you can see from the screen). Is it not possible to make the camera have a height that perfectly covers the height of the background?

    Running the code on a mobile device, I encounter problems in the click of many objects that have been placed inside the room through normal coordinates (they are displayed correctly). Do I have to place them by code based on other coordinates?
     
    Last edited: Apr 15, 2019
  44. Pixelated_Pope

    Pixelated_Pope Member

    Joined:
    Jun 20, 2016
    Posts:
    780
    Okay, first off, since you are developing your game for a mobile device in portrait mode but aren't developing your game on a monitor in portrait mode, you will need to replace "display_get_width & height" with hard coded values to get your game window to display properly when building locally.

    As for your other issues with GUI elements, that's a completely different issue, but one I've also released a video on:


    It's a complicated problem, but this is how I solve it for my projects that support different aspect ratios.

    It also seems you are using the older version of my system. You may be interested in my Super Simple system:
     

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