This is a script I found among my old Game Maker files. It was created by Monkey Dude – all credits to him – and it is very good and interesting and therefore I want to explain it here.
<div style="clear: both;">var xx, yy;
xx = argument0.x - view_wview[0]/2
xx = max(xx, 0)
xx = min(xx, room_width - view_wview[0])
yy = argument0.y - view_hview[0]/2
yy = max(yy, 0)
yy = min(yy, room_height - view_hview[0])
xx = round(xx/view_wview[0])*view_wview[0]
yy = round(yy/view_hview[0])*view_hview[0]
if xx < view_xview[0]
{
view_xview[0] -= view_wview[0]/10
}
if xx > view_xview[0]
{
view_xview[0] += view_wview[0]/10
}
if yy < view_yview[0]
{
view_yview[0] -= view_hview[0]/10
}
if yy > view_yview[0]
{
view_yview[0] += view_hview[0]/10
}</div>
Argument 0 is the object that the view should follow. The script assumes that we use view index number 0. The first three calculations decides whether the object is on the left or right side in the view, and whether there is enough space on the right and left to create a new view.
xx = round(xx/view_wview[0])*view_wview[0]
yy = round(yy/view_hview[0])*view_hview[0]
The final calculations decide where in the view the player is. Now when that is figured out, based upon whether the object goes out of the screen at left side, right side, up or down. Note that it’s done in percentage. Ten percent of a room measuring 10 000 pixels might be to big, while it might be okay with 1000 pixels. Change the values for your needs.
.
Users logged in:
Comments
Loading comments...