1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GML Maintain low resolution look but with a smooth camera?

Discussion in 'Programming' started by hdarren, May 17, 2019 at 2:47 PM.

  1. hdarren

    hdarren Member

    Joined:
    Jun 21, 2016
    Posts:
    269
    My game's base resolution is 256x144 and using the window_set_size() I can upscale the game to whatever size I like whilst maintaining that pixel perfect on-the-grid look. However this can make for a very janky camera as the view is also forced to the grid. I've tried using the surface_resize() function which gives a very silky smooth camera as it isn't forced to the grid, but unfortunately everything else is too which can make some image manipulations like using image_angle and image_scale go off-grid which loses that low resolution look.

    So is there a way of making the camera have that silky smooth off grid movement, but make it so everything else sticks to the grid?
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,249
    if you make the view two pixels larger (+1 in each direction) and draw it to a surface, you can then draw that surface in Draw GUI event while offsetting it as per sub-pixel offset
     
    hdarren and Pfap like this.
  3. hdarren

    hdarren Member

    Joined:
    Jun 21, 2016
    Posts:
    269
    Hmm... thank you but I'm struggling to wrap my head around this. I have a Camera object that follows the player, and I made a Canvas object that now draws the application_surface to the screen via Draw GUI. But how do I work out what offset to use?
     
  4. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,249
    The offset is merely the difference between where the view should be looking at (with fractions) and where the camera is showing it (rounded coordinates)
     
    hdarren likes this.
  5. hdarren

    hdarren Member

    Joined:
    Jun 21, 2016
    Posts:
    269
    I'm very sorry I am not understanding the process.

    1) In my room I have set the Camera Properties and Viewport Properties to have Width:258 and Height:146.

    2) At the beginning of my game I use this code "window_set_size(256*4,144*4);" to upscale the game window so it isn't tiny.

    3) In my Camera object it moves towards the Player object so it smoothly moves towards him. I use the camera_set_view_pos() function to set the camera (including fractions).

    4) In my Canvas object in the Draw GUI I use "draw_surface(application_surface,0,0)" to draw the screen.

    Is this the correct process to use? And which value would I use to get the correct fraction?

    I'm very sorry for being dumb but the way cameras work with views and surfaces really confuses me. :(


    ///edited
    I am trying to get the offset code but I don't know if I'm doing this correct.

    Code:
    if round(Camera.x) > Camera.x {vx = 1-(round(Camera.x)-Camera.x);}
    else if round(Camera.x) < Camera.x {vx = Camera.x-round(Camera.x);}
    draw_surface(application_surface,vx,vy);
    
    It still appears janky so I'm unsure if this is the right track. :(
     
    Last edited: May 19, 2019 at 10:24 AM

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