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

Camera troubleshooting

R

r0sh

Guest
I'm having some issues with camera and updating views. I have a camera object with the following create and step events. A lot of this was pulled from Shawn S's platformer tutorial.
Create event.
Code:
cam = view_camera[0];
follow = objPlayer;
view_w_half = camera_get_view_width(cam) * 0.05;
view_h_half = camera_get_view_height(cam) * 0.05;
xTo = xstart;
yTo = ystart;
Step event:
Code:
if (instance_exists(follow)) {
   xTo = follow.x;
   yTo = follow.y;
}

x += (xTo - x) / 25;
y += (yTo - y) / 25;


camera_set_view_pos(cam, x - view_w_half, y - view_h_half);
show_debug_message("xTo: " + string(xTo) + " yTo: " + string(yTo) + " Cam x: " + string(x) + " Cam y: " + string(y))
show_debug_message("where cam should be: " + " viewWHalf: " +string(x-view_w_half) + " viewYHalf: " + string(y-view_h_half));
show_debug_message("CamX: " + string(camera_get_view_x(cam)) + " CamY: " + string(camera_get_view_y(cam)));
show_debug_message("objX: " + string(x) + " objY: " + string(y));
The debug messages show everything updating appropriately, but the camera view is not updating on screen. I've added the camera object to room. The camera view just stays at 0,0. Not sure exactly what's happening here.


Edit: it looks like my view port x and y are not being updated..

Edit2: This started working.... /shrug
 
Last edited by a moderator:

YoSniper

Member
I have never used camera_set_view_pos. Instead, I usually manipulate view_xview and view_yview directly. Their counterparts are view_xport and view_yport. The "view" variables change the coordinates in the view in the room, whereas the "port" variables change where the game window appears on your screen; I never touch those.
 

samspade

Member
One issue with this is you're using the variable cam instead of view_camera[0]. This means that in the create event you are saving the camera id at that point to the variable cam, then using that specific camera id later on. However, there is no guarantee that camera id will still be correct if you are changing rooms. You need to be checking it every time.

Personally I would use a macro for this (taken from pixelated pope's tutorial):

Code:
#macro VIEW view_camera[0]
You can then do:

Code:
camera_set_view_pos(VIEW, x - view_w_half, y - view_h_half);
 
Top