How would I prevent my camera from seeing outside the room

Niften

Member
How would I prevent my camera from seeing outside the room?
CREATE
Code:
#macro CAMERA_WIDTH 1024
#macro CAMERA_HEIGHT 768

camera = camera_create();

var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
var pm = matrix_build_projection_ortho(CAMERA_WIDTH/3,CAMERA_HEIGHT/3,1,10000);

camera_set_view_mat(camera,vm);
camera_set_proj_mat(camera,pm);

view_camera[0] = camera;

follow = obj_player;
xTo = x;
yTo = y;

game_set_speed(60, gamespeed_fps);
STEP
Code:
x += (xTo - x)/10;
y += (yTo - y)/10;

//x = xTo;
//y = yTo;

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);
 
Put a clamp on it!

view_xview = clamp(view_xview, 0, room_width - view_wview)
view_yview = clamp(view_yview, 0, room_height - view_hview)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Doesn't work in GameMaker 2, that's why I was asking
Yes it does, as long as you change the view_x/yview array to use the appropriate functions...

Code:
var _vx = clamp(camera_get_view_x(view_camera[0]), 0, room_width - camera_get_view_width(view_camera[0]));
var _vy = 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], _vx, _vy);
 
Top