W
Warmachine33
Guest
Ok so I'm working on a top down RPG and I want to make it up to four players locally can join. So far I just made a second player and put him in the game, but when I move him the camera does not stay centered on both of them. So I want to try to do 2 things I want the camera to stay center on the players when they are close to each other and if it is possible when they leave the area the camera switches to split screen. I will put the code I have for my camera below and if you need more info let me know, appreciate any help. //obj_camera room start event
//obj_camera end step event
GML:
//camera
view_enabled = true;
view_visible[0] = true;
scale = 5;
var cam = camera_create_view(0, 0, RESOLUTION_W, RESOLUTION_H, 0, -1, -1, -1, RESOLUTION_W/2, RESOLUTION_H/2);
view_set_camera(0,cam);
window_set_size(RESOLUTION_W*scale, RESOLUTION_H*scale);
surface_resize(application_surface, RESOLUTION_W*scale, RESOLUTION_H*scale);
Code:
var CW = camera_get_view_width(view_camera[0]);
var CH = camera_get_view_height(view_camera[0]);
var CX = oplayer.x - CW/2;
var CY = oplayer.y - CH/2;
//clamp
CX = clamp(CX, 0, room_width - CW);
CY = clamp(CY, 0, room_height - CH);
//small rooms
if(room_width<CW || room_height<CH){
CX = room_width/2 - CW/2
CY = room_height/2 - CH/2;
}
camera_set_view_pos(view_camera[0], CX, CY);
Last edited by a moderator: