D
Dekadrachm
Guest
Hello, I have created a camera object to handle control of the players camera. On the title screen of my game, the text I have displayed is off centered, as if in the placement of the camera is wrong. In game, the camera propely follows the player, but another function was added to "edge" detect the boundaries of the room to stop the camera from going past that point. This does not work propely, the camera will stop near the edge, but the player will still wrap before actually touching the edge of the screen.
This script is executed as a room start script, the camera is placed in the home room and is checked as persistent.
This part is where the title screen is having issues not being centered.
This script is where target checking is performed to attach the camera using a step event.
My issue appears to be with the "clamp" function,
The player object has a wrap function to teleport itself to the opposite boundary upon exiting the room boundary. The wrap gets triggered before the object reaches the edge of the screen. my guess is either both problems are being caused by the same thing, or something went wrong with the clamp function.
I was actually watching a tutorial to get the main structure and followed it exact, long story short, their verison worked and mine half-works.
GML:
/// @player camera set-up
// camera
cameraX = 0;
cameraY = 0;
target = obj_player;
camerawidth = 960;
cameraheight = 540;
view_enabled = true;
view_visible[0] = true;
camera_set_view_size(view_camera[0], camerawidth, cameraheight);
//display
displayscale = 2;
displaywidth = camerawidth * displayscale;
displayheight = cameraheight * displayscale;
window_set_size(displaywidth,displayheight);
surface_resize(application_surface, displaywidth, displayheight);
alarm[0] = 10;
This part is where the title screen is having issues not being centered.
Code:
// follow target
if (instance_exists(target)){
cameraX = target.x - (camerawidth/2);
cameraY = target.y - (cameraheight/2);
cameraX = clamp(cameraX, 0, room_width - cameraheight);
cameraY = clamp(cameraY, 0, room_height - cameraheight);
camera_set_view_pos(view_camera[0], cameraX, cameraY);
}
My issue appears to be with the "clamp" function,
The player object has a wrap function to teleport itself to the opposite boundary upon exiting the room boundary. The wrap gets triggered before the object reaches the edge of the screen. my guess is either both problems are being caused by the same thing, or something went wrong with the clamp function.
I was actually watching a tutorial to get the main structure and followed it exact, long story short, their verison worked and mine half-works.