Legacy GM how to make view follow a sprite

Edu Shola

Member
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
 
I

Ian

Guest
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:

Simple cutscene i have but can be applied to anything
 
Last edited by a moderator:

Alexx

Member
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

Member
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:

Simple cutscene i have but can be applied to anything
###
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
 

Edu Shola

Member
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;
###
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?
 
A

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

Member
Thanks for
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.
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.
I don't really understand your code, could you please explain more. I'm kinda lost
 
A

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. ^^'
 
Top