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

GML Issues with camera settings.

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.
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 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.

Capture.PNG

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);
}
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.
 
D

Dekadrachm

Guest
Another note, if I change the room size of the title screen room to match the x and y size of the camera, the title screen displays properly.
 
D

Dekadrachm

Guest
Solved half the problem, saw I put cameraheight instead of camerawidth in the clamp function. Only issue now is getting the camera to focus properly in rooms when a target isn't defined and the room size is greater than the camera size.
 
Top