External Exam Download Resources Web Applications Games Recycle Bin

two player camera | gml

CAMERAROOM Create

cam = view_get_camera(0);
cam_x = 0;
cam_y = 0;
cam_minWidth = 1366/4;
cam_minHeight = 768/4;
cam_width = cam_minWidth;
cam_height = cam_minHeight;
cam_aspect = cam_minWidth/cam_minHeight
cam_xBuffer = 100;
cam_yBuffer = 100;

CAMERAROOM Step

//set x and y
cam_x = (Player1.x+Player2.x)/2
cam_y = (Player1.y+Player2.y)/2

//set base width & hight
cam_width = max(point_distance(Player1.x,0,Player2.x,0)+cam_xBuffer,cam_minWidth)
cam_height = max(point_distance(0,Player1.y,0,Player2.y)+cam_yBuffer,cam_minHeight)

//fix aspect ratios for width and height
var cur_aspect;
cur_aspect = max(cam_width,cam_height*cam_aspect)
cam_width = cur_aspect
cam_height = cur_aspect/cam_aspect

camera_apply(cam)
camera_set_view_pos(cam,cam_x-cam_width/2,cam_y-cam_height/2);
camera_set_view_size(cam,cam_width,cam_height);