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

Setting up the Camera Issues

K

KarateMan

Guest
Hey Guys, Im having some issues setting up a rotating camera. right now My code for the camera is
view_camera[0] = camera_create_view(0,0,1024,768,0,noone,-1,-1,-1,-1);
view_visible[0] = true;
view_visible[1] = false;
view_visible[2] = false;
view_visible[3] = false;
view_visible[4] = false;
view_visible[5] = false;
view_visible[6] = false;
view_visible[7] = false;
view_enabled = true;
This is because for some reason a different view for some reason was overriding my view 0 and not letting me rotate it. Before it looked like this
upload_2018-7-25_17-37-12.png
While it didnt rotate it atleast was showing me the full room. once i changed the camera code to what is picture above, it looked like this:
upload_2018-7-25_17-38-28.png
When its like this however, I can rotate the camera, so at least that is working.
Any idea of how to center the camera? as it stands for some reason the camera is capturing outside of the room itself. Any help would be awesome!
 

Slyddar

Member
Try clamping the view so it only moves between your room dimensions. Put this in a step event of an obj_camera object, or similar.

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

KarateMan

Guest
Try clamping the view so it only moves between your room dimensions. Put this in a step event of an obj_camera object, or similar.

Code:
var xx = clamp(camera_get_view_x(view_camera[0]), 0, room_width - camera_get_view_width(view_camera[0]));
var yy = 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], xx, yy);
Tried this, Still getting the problem of the off center camera. could it be something else interfering with where I placed the camera in the create event? As far as I understand the camera_create_view command im placing it so that it should be encompassing the entire screen....
 

Slyddar

Member
When you say rotate the camera, are you actually rotating the view? The pictures don't show any rotation.

It looks like the camera is centering on where the icon for whatever object is running the camera is located. Are you making the camera follow an object?

This should work for following an o_player object, but if you're not following anything, just remove the o_player references and the camera should center the room. Not sure about your rotating part though.
Code:
//create event
camera = camera_create_view(0,0,1024,768,0,noone,-1,-1,-1,-1);
view_set_camera(0, camera);
view_camera[0] = camera;
view_visible[0] = true;
view_enabled = true;
Code:
//step event
if instance_exists(o_player)
camera_set_view_pos(camera, o_player.x - camera_get_view_width(camera)/2, o_player.y - camera_get_view_height(camera)/2);

//clamp camera
var xx = clamp(camera_get_view_x(camera), 0, room_width - camera_get_view_width(camera));
var yy = clamp(camera_get_view_y(camera), 0, room_height - camera_get_view_height(camera));

camera_set_view_pos(camera, xx, yy);
 
Last edited:
K

KarateMan

Guest
When you say rotate the camera, are you actually rotating the view? The pictures don't show any rotation.

It looks like the camera is centering on where the icon for whatever object is running the camera is located. Are you making the camera follow an object?

This should work for following an o_player object, but if you're not following anything, just remove the o_player references and the camera should center the room. Not sure about your rotating part though.
Code:
//create event
camera = camera_create_view(0,0,1024,768,0,noone,-1,-1,-1,-1);
view_set_camera(0, camera);
view_camera[0] = camera;
view_visible[0] = true;
view_enabled = true;
Code:
//step event
if instance_exists(o_player)
camera_set_view_pos(camera, o_player.x - camera_get_view_width(camera)/2, o_player.y - camera_get_view_height(camera)/2);

//clamp camera
var xx = clamp(camera_get_view_x(camera), 0, room_width - camera_get_view_width(camera));
var yy = clamp(camera_get_view_y(camera), 0, room_height - camera_get_view_height(camera));

camera_set_view_pos(camera, xx, yy);
hey so I tried this, and it works great, but when I do it now, the bottom/top of the screen gets cut out when the camera is rotating 90 degrees.
example:upload_2018-7-28_17-59-26.png
Theres more space down below but the camera wont pan down, is this an issue with the room size?
 

Slyddar

Member
If you are rotating the camera, you will probably need to change the formulas as the width and height of the room are still the same, but you want them to now swap.
 
Top