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

Question About Cameras

I

Isaac Roberts

Guest
I need to switch which object the camera is centered around, I made a different viewport, but can't figure out how to switch it. I also tried this code


var cam = camera_create_view(0, 0, 1920, 1080, 0, Obj_Camera, 10, 10, 920, 580);
view_set_visible(1,cam)
view_set_camera(1,cam)

But that just makes the camera centered on the top left.
Anyone know how to switch viewports? Thanks!
 

samspade

Member
There's couple ways to do it. The simplest way is to use the built in camera functions. To assign the camera you would use:

view_camera[0] = cam;

You can also use functions like camera_set_view_* to do things like change the camera's target, follow rate, angle, and so on. Additionally, virtually all default functions have a corresponding place in the room editor where they can simply be set.

The default camera functions can get you pretty far. There are some limitations however. For example, the default camera follow system won't move outside of the room.

You can use some of the more complicated functions though for more control. For example:

Code:
//create event
CAMERA = camera_create();
var view_mat = matrix_build_lookat(xx, yy, -10, xx, yy, 0, 0, 1, 0);
var proj_mat = matrix_build_projection_ortho(camera_width, camera_height, 1, 10000);
camera_set_view_mat(CAMERA, view_mat);
camera_set_proj_mat(CAMERA, proj_mat);


//view variables
view_camera[0] = CAMERA;

//step event
var view_mat = matrix_build_lookat(xx, yy, -10, xx, yy, 0, 0, 1, 0);
camera_set_view_mat(CAMERA, view_mat);
You would have to create the various variables yourself of course.

For more information see this thread: https://forum.yoyogames.com/index.p...pdating-the-view-correctly.43952/#post-271079

or look for Shaun Spalding's GMS 2 camera tutorial on YouTube.
 
D

dugtrioramen

Guest
I need to switch which object the camera is centered around, I made a different viewport, but can't figure out how to switch it. I also tried this code


var cam = camera_create_view(0, 0, 1920, 1080, 0, Obj_Camera, 10, 10, 920, 580);
view_set_visible(1,cam)
view_set_camera(1,cam)

But that just makes the camera centered on the top left.
Anyone know how to switch viewports? Thanks!
camera_set_view_target
for changing the object
 
Top