[SOLVED] GM2 Cameras: understanding the basics of how they work

Bentley

Member
I'm used to GM1's views so I've been struggling with GM2's cameras. I understand that you can set the view size and the port through the room editor, like you could in GM1. But I'm trying to "go with the tide" for lack of a better phrase, so I want to create a camera, a port, and a view through code.

Code:
view_enabled = true;
view_visible[0] = true;

// Create Camera
global.cam = camera_create();

// Port
view_set_visible(0, true); // Make the port visible
view_set_camera(0, global.cam); // Assign the camera to port 0
view_set_xport(0, 0); // Port dimensions
view_set_yport(0, 0);
view_set_wport(0, 100); // This is 100x100 to test whether it's working, which it' not : (
view_set_hport(0, 100);

// View
camera_set_view_pos(global.cam, 0, 0);
camera_set_view_size(global.cam, CAM_WIDTH, CAM_HEIGHT);
camera_set_view_border(global.cam, CAM_WIDTH / 2, CAM_HEIGHT / 2);
camera_set_view_target(global.cam, id);
As far as I can tell, none of the "port" code works, and it screws up the rest of the code. If I understand what ports are, then I should have a tiny game window (100x100) that shows what the view shows.

If anyone can explain the basics of cameras / views / ports I would greatly appreciate it. If you can point me to a blog that would be great too. Anything would help. Thanks for reading.
 
Last edited:
M

maratae

Guest
[Room Start]
Code:
//Enable views
view_set_visible(0, true);
view_set_wport(0, GAME_WIDTH);
view_set_hport(0, GAME_HEIGHT);
//Camera
view_camera[0] = camera_create_view(0, 0, GAME_WIDTH, GAME_HEIGHT, 0, -1, -1, -1, 0, 0);
[Step]
Code:
pos_x = player.x - (camera_get_view_width(view_camera[0]) / 2);
pos_y = player.y - (camera_get_view_height(view_camera[0]) / 2);
camera_set_view_pos(view_camera[0], pos_x, pos_y);
[Room End]
Code:
camera_destroy(view_camera[0])
( Edited for more detail, but it can be really simple. )
( GAME_WIDTH and GAME_HEIGHT are my real resolution constants )
 

Bentley

Member
Code:
pos_x = player.x - (camera_get_view_width(view_camera[0]) / 2);
pos_y = player.y - (camera_get_view_height(view_camera[0]) / 2);
camera_set_view_pos(view_camera[0], pos_x, pos_y);
That's all she wrote.
Haha, thanks for the reply. I will use that : ) SOLVED
 
M

maratae

Guest
[Room Start]
Code:
//Enable views
view_set_visible(0, true);
view_set_wport(0, GAME_WIDTH);
view_set_hport(0, GAME_HEIGHT);
//Camera
view_camera[0] = camera_create_view(0, 0, GAME_WIDTH, GAME_HEIGHT, 0, -1, -1, -1, 0, 0);
[Step]
Code:
pos_x = player.x - (camera_get_view_width(view_camera[0]) / 2);
pos_y = player.y - (camera_get_view_height(view_camera[0]) / 2);
camera_set_view_pos(view_camera[0], pos_x, pos_y);
[Room End]
Code:
camera_destroy(view_camera[0])
( Edited for more detail, but it can be really simple. )
( GAME_WIDTH and GAME_HEIGHT are my real resolution constants )
PS: This is my actual game code.
Haha, thanks for the reply. I will use that : ) SOLVED
PS2: Glad to help.
 
Top