GM:S 1.4 how to make view follow a sprite

Discussion in 'Programming' started by Edu Shola, Jul 2, 2016.

  1. Edu Shola

    Edu Shola Member

    Joined:
    Jul 1, 2016
    Posts:
    18
    Hello guys :), I created a level select room that's is 720 *2560 and I set the view to only show 720 *1280.the room is filled with numbered objects for different levels, and when a new level is unlocked the sprite changes to spr_indicator. I need the view to follow the spr_indicator so it centers on it for players to know where to go next. gml or drag n drop is welcome, I have seen such in games like candy crush, Angry Birds, etc. Thanks in advance
     
  2. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    is spr_indicator an object or did u use draw_sprite(); for it?

    EDIT:
    It also looks like you want a smooth transition instead a snap kinda like this:
    [​IMG]
    Simple cutscene i have but can be applied to anything
     
    Last edited: Jul 2, 2016
    Piyo and Edu Shola like this.
  3. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    436
    You would need to set an object to follow, not a sprite.
    Something like this in code, assuming view is set up & visible in room editor:

    Code:
    view_object[0]=obj_follow;//set object to follow
    view_hborder[0] = view_wview[0] / 2;
    view_vborder[0] = view_hview[0] / 2;
    
     
    Edu Shola likes this.
  4. Edu Shola

    Edu Shola Member

    Joined:
    Jul 1, 2016
    Posts:
    18
    ###
    actually the spr_indicator is just a sprite and the level object sprite changes to spr_indicator when the level is newly unlocked.both smooth and snap will work I just want the view centered on it
     
  5. Edu Shola

    Edu Shola Member

    Joined:
    Jul 1, 2016
    Posts:
    18
    ###
    That's a good idea, so I was thinking I could setup an invisible object and increase its movement on y axis after a certain level is unlocked. Because the spr_indicator is only a sprite and it replaces the current sprite for the newly unlocked level. Do you understand?
     
  6. Aura

    Aura Guest

    Code:
    if (obj_levelexit.sprite_index == spr_indicator and alarm[0] < 120 and shown == false)
    {
         view_object[0] = obj_levelexit;
        view_hborder[0] = view_wview[0] / 2;
        view_vborder[0] = view_hview[0] / 2;
    }
    
    In the Alarm 0 event, reset view_object[0] to obj_player and set shown to true.
     
    Edu Shola likes this.
  7. Edu Shola

    Edu Shola Member

    Joined:
    Jul 1, 2016
    Posts:
    18
    Thanks for
    I don't really understand your code, could you please explain more. I'm kinda lost
     
  8. Aura

    Aura Guest

    The code basically checks if the level object's sprite_index to equal to spr_indicator (which is used to indicate that the exit is now open I guess), then it checks if alarm[0] is smaller than 0. That is so because if we won't do it, it would keep getting reset to 120 and the alarm event would never get triggered, and the view focus won't return to the player object. shown is simply a variable which tells if the level exit object has already been shown or not. In the Alarm event, it is set to true, so that the view focus doesn't remain on the level exit object and returns to the player object. I hope that clarifies your doubts. ^^'
     

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