• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

SOLVED [Problem] Adapt the camera to room size

I am doing an action rpg but I have a problem when creating small rooms (shorter than the width of the camera or lower than the height of the camera) since the camera, due to the edges that I put on it, moves from place to leave the room instead of staying in it, so the room is on one side of the screen and only the background is on the other side. If someone has a way to make the camera stay inside the room and make it appear centered I would really appreciate it (centered I mean leaving a black void around the room to fill the space the camera needs and that the room is in the center of the screen)
 
create event of camera
viewWidthHalf = camera_get_view_width(cam) * 0.5;
viewHeightHalf = camera_get_view_height(cam) * 0.5;

step event of camera
//keep camera centered inside room
x = clamp(x, viewWidthHalf, room_width-viewWidthHalf);
y = clamp(y, viewHeightHalf, room_height-viewHeightHalf);

hope this helps!
 
Thank you
create event of camera
viewWidthHalf = camera_get_view_width(cam) * 0.5;
viewHeightHalf = camera_get_view_height(cam) * 0.5;

step event of camera
//keep camera centered inside room
x = clamp(x, viewWidthHalf, room_width-viewWidthHalf);
y = clamp(y, viewHeightHalf, room_height-viewHeightHalf);

hope this helps!
Thank you
 
Top