GMS 2 Camera Not Activating

S

Spencer S

Guest
I have the following code in the creation code of my room:
Code:
camera = camera_create_view(0, 0, 640, 480, 0, obj_player, 5, 5, -1, -1);
var viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0);
var projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0);
camera_set_view_mat(camera, viewmat);
camera_set_proj_mat(camera, projmat);
This isn't applying at all. No matter what I seem to code, it doesn't apply to my current camera. What line am I missing, or what am I typing wrong? I want to control the camera and view purely through the creation code of my room.
 

samspade

Member
I have the following code in the creation code of my room:
Code:
camera = camera_create_view(0, 0, 640, 480, 0, obj_player, 5, 5, -1, -1);
var viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0);
var projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0);
camera_set_view_mat(camera, viewmat);
camera_set_proj_mat(camera, projmat);
This isn't applying at all. No matter what I seem to code, it doesn't apply to my current camera. What line am I missing, or what am I typing wrong? I want to control the camera and view purely through the creation code of my room.
At a minimum you need to enable views and assign the camera to a view.

This tutorial uses a similar system to what you're using:

 
C

CobaltBW

Guest
I have the following code in the creation code of my room:
Code:
camera = camera_create_view(0, 0, 640, 480, 0, obj_player, 5, 5, -1, -1);
var viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0);
var projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0);
camera_set_view_mat(camera, viewmat);
camera_set_proj_mat(camera, projmat);
This isn't applying at all. No matter what I seem to code, it doesn't apply to my current camera. What line am I missing, or what am I typing wrong? I want to control the camera and view purely through the creation code of my room.
I ran into a similar issue earlier today and found that the best camera process seems to be different depending on whether you're using Studio 1 or 2. If you're using GMS1, the above tutorial should do just fine; I'm using GMS2, and found that it's actually simpler than that and doesn't require matrices.

Creation code:
Code:
camera = camera_create_view(0, 0, <screenwidth>, <screenheight>, 0, -1, -1, -1, 32, 32)
view_enabled = 1
view_visible[0] = 1
view_set_camera(0, camera)
target = <followobject>
Step code:
Code:
x = target.x
y = target.y
camera_set_view_pos(camera,x-(camera_get_view_width(camera)/2),y-(camera_get_view_height(camera)/2))
var X = clamp(camera_get_view_x(camera), 0, room_width - camera_get_view_width(camera))
var Y = clamp(camera_get_view_y(camera), 0, room_height - camera_get_view_height(camera))
camera_set_view_pos(camera, X, Y)
I don't know of any good method of controlling the camera that doesn't at least require a step event, but if your concern is that you can code the camera once and forget about it, simply plug the code into a persistent object and put the creation code in its room start event (remembering to destroy the camera on room end to prevent memory leaks).
 
Top