How to keep the camera view to within room dimensions

by Xmas is coming   Last Updated November 08, 2018 21:13 PM

    me = self;
    view_yview[0] += ( me.y-(view_hview[0]/2) - view_yview[0]) * 0.1;
    view_xview[0] += ( me.x-(view_wview[0]/2) - view_xview[0]) * 0.3;

This is the code I use to smooth camera movement in game maker. But it's going beyond the room dimensions; showing stuff that shouldn't be shown, as the camera should stop following the player at a point.

How do I achieve this?



Answers 1


Try adding:

view_xview[0] = round(median(0, room_width - view_wview[0] - 1, view_xview[0]));
view_yview[0] = round(median(0, room_height - view_hview[0] - 1, view_yview[0]));

and you need not use me and self:

view_xview[0] += (x - view_wview[0] / 2 - view_xview[0]) * 0.3;
view_yview[0] += (y - view_hview[0] / 2 - view_yview[0]) * 0.1;
Dmi7ry
Dmi7ry
November 14, 2015 06:08 AM

Related Questions


Directional, Smooth scaling

Updated July 15, 2016 08:05 AM


Collision-based Camera Repositioning

Updated November 06, 2017 19:13 PM