• 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!

GameMaker GameMaker Studio 2 Camera's showing outside of the room.

N

NoFontNL

Guest
Quick question, may be quick answer. My camera is showing me the outside part of the room, how do I set the camera to not view outside the room?
 

Slyddar

Member
Try using clamp to limit the movement of the camera.

In the step event of your camera, add something like this:

Code:
var xx = clamp(camera_get_view_x(view_camera[0]), 0, room_width - camera_get_view_width(view_camera[0]));
var yy = clamp(camera_get_view_y(view_camera[0]), 0, room_height - camera_get_view_height(view_camera[0]));

camera_set_view_pos(view_camera[0], xx, yy);
 
N

NoFontNL

Guest
When I do that, it just only shows me the background color (outside the room?)
 
N

NoFontNL

Guest
obCamera :: Create
Code:
camera = camera_create();
var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var pm = matrix_build_projection_ortho(144,256,1,10000);
camera_set_view_mat(camera,vm);
camera_set_proj_mat(camera,pm);
view_camera[0] = camera;
if (room != rmTitleScreen) follow = obPlayer; else follow = obTitleScreenFollow;
xTo=x;
yTo=y;
obCamera :: Step
Code:
    if (room == rmTitleScreen) {
        x+=(xTo-x)/6;
        y+=(yTo-y)/6;
    } else {
        x+=(xTo-x)/8;
        y+=(yTo-y)/8;
    }
    if (follow != noone) {
        xTo = follow.x;
        yTo = follow.y;
    }
    var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
    camera_set_view_mat(camera,vm);
 
N

NoFontNL

Guest
I fixed it myself, was at first trying to do something with the view mat, but got a cool rotation 3d effect.
3d effect was:
var vm = matrix_build_lookat(x,y,-10, x = clamp(x, HALF_OF_VIEW_WIDTH, room_width-HALF_OF_VIEW_WIDTH),clamp(y, HALF_OF_VIEW_HEIGHT, room_height-HALF_OF_VIEW_HEIGHT),0,0,1,0);

Solution for me: added:
x = clamp(x, 72, room_width-72); // 72 and 128 are half my room width and height.
y= clamp(y,128, room_height-128);
after the if (follow) statement.
 
Top