Create your player object (make your player persistent) and put this in the Create Event:
lvx=view_xview[0]
lvy=view_yview[0]
global.transition = 0;
global.transDir = ""
global.viewTargX = 0;
global.viewTargY = 0;
Then make an End Step event and make a pice of code containing this (Replace objLink with your player object):
//Check if player is outside the view
if (global.transition) exit;
vx = view_xview[0] //Set up some placeholders to save space
vw = view_wview[0]
vy = view_yview[0]
vh = view_hview[0]
if (objLink.x< vx)
{
global.transDir = "left"
global.transition = 1;
global.viewTargX = (vx-vw)
}
else if ((objLink.x+objLink.sprite_width) > vx+vw)
{
global.transDir = "right"
global.transition = 1;
global.viewTargX = (vx+vw)
}
else if (objLink.y< vy)
{
global.transDir = "up"
global.transition = 1;
global.viewTargY = (vy-vh)
}
else if ((objLink.y+objLink.sprite_height) > vy+vh)
{
global.transDir = "down"
global.transition = 1;
global.viewTargY = (vy+vh)
}
then Put another piece of code after that containing this (Replace objLink with your player object):
if (!global.transition) exit;
//Check if the view is in the right place and, if not, move it closer
//Move Right
if (global.viewTargX > view_xview[0])
{
view_xview[0] += 16;
objLink.x+=1.8
lvx=view_xview[0]
lvy=view_yview[0]
}
else if global.transDir = "right"
{view_xview[0] = global.viewTargX; global.transition = 0}
//Move left
if (global.viewTargX < view_xview[0])
{
view_xview[0] -= 16;
objLink.x-=1.8
lvx=view_xview[0]
lvy=view_yview[0]
}
else if global.transDir = "left"
{view_xview[0] = global.viewTargX; global.transition = 0}
//Move down
if (global.viewTargY > view_yview[0])
{
view_yview[0] += 16;
objLink.y+=2
lvx=view_xview[0]
lvy=view_yview[0]
}
else if global.transDir = "down"
{view_yview[0] = global.viewTargY; global.transition = 0}
//Move up
if (global.viewTargY < view_yview[0])
{
view_yview[0] -= 16;
objLink.y-=2
lvx=view_xview[0]
lvy=view_yview[0]
}
else if global.transDir = "up"
{view_yview[0] = global.viewTargY; global.transition = 0}
Then go in your room and put this in the Creation Code (Replace objLink with your player object):
if(instance_exists(objLink)){
view_xview=objLink.lvx
view_yview=objLink.lvy
}
This especially goes to moree so he won't have mind boggling problems on howto fix it up.