• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED [Problem] Adapt the camera to room size

F

FranciscoJGamer

Guest
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!
 
F

FranciscoJGamer

Guest
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