1. 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

GM:S 1.4 Question about Aspect Ratio while zooming

Discussion in 'Programming' started by Kinetic, Jun 25, 2016.

  1. Kinetic

    Kinetic Guest

    Hello,

    I'm currently making a game where the view object stays within two players.
    When players get further apart I made it so the camera zooms.
    But the view isn't keeping it's aspect ratio.

    Could anyone please help me out?

    x = (obj_player.x + obj_player2.x) / 2;
    y = (obj_player.y + obj_player2.y) / 2;

    view_wview = max(abs(obj_player.x-obj_player2.x),320);
    view_hview = max(abs(obj_player.y-obj_player2.y),180);

    Here's the current code for my view object.

    I appreciate any help :)

    Kind regards,

    Kinetic
     
  2. rui.rosario

    rui.rosario Guest

    I'm assuming you want the 320x180 aspect ratio. If so, you can try something like:

    Code:
    var mWid = min(abs(obj_player.x - obj_player2.x), 320);
    var mHei = min(abs(obj_player.y - obj_player2.y), 180);
    
    var rWid = mHei * 320 / 180;
    var rHei = mWid * 180 / 320;
    
    if (mHei < rHei) {
        view_wview = mWid;
        view_hview = rHei;
    } else if (mWid < rWid) {
        view_wview = rWid;
        view_hview = mHei;
    } else {
        view_wview = mWid;
        view_hview = mHei;
    }
    
    This code is untested, so I would play around a bit. Hopefully it'll help you get on track
     
    Last edited by a moderator: Jun 25, 2016
  3. Kinetic

    Kinetic Guest

    It gives an error straight away for the variables not being set before calling them.


    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object obj_view:

    Variable obj_view.mHei(100020, -2147483648) not set before reading it.
    at gml_Object_obj_view_StepNormalEvent_1 (line 4) - rWid = mHei * 320 / 180;
    ############################################################################################
     
  4. rui.rosario

    rui.rosario Guest

    Sorry placed the code tag in the wrong place XDDD edited
     
  5. Kinetic

    Kinetic Guest

    Works better, doesn't follow the players though :/ Time to play with that piece of code for a bit.
     
  6. rui.rosario

    rui.rosario Guest

    It doens't follow because I didn't copy the setting of the x and y variables, so just add
    Code:
    x = (obj_player.x + obj_player2.x) / 2;
    y = (obj_player.y + obj_player2.y) / 2;
    
    Before the rest of the code
     
  7. Kinetic

    Kinetic Guest

    I'll keep playing with the code a little, still not perfect. But way better than what I had.

    If anyone has some further suggestions, you're very welcome :)
     
    Last edited by a moderator: Jun 25, 2016

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