F
Finn
Guest
Views and cameras have undergone lots of changes with the shift from 1.4 to 2 and then again within the 2.X builds. There are a lot of tutorials and guides available on handling cameras many of which are out-dated.
I found that some of the camera handling I did for GML2 (specifically setting proj. & view matrices directly) would not work properly anymore with any build after V 2.1.4.218 - causing strange flickering effects when using surfaces - even though the camera system worked flawless before.
With any build after 2.1.4.218 whenever I would set the drawing target to any surface GMS2 would start drawing any draw event that came after that line of code in random positions (including tileset layers).
1) DESTROYING CAMERAS
Whenever starting a new room the camera of the previous room will be destroyed using the following script and a new one will be created using the room's properties. The code below is furthermore used in the clean_up event of the camera object to avoid potential memory leaks.
2) CREATING CAMERAS
The camera object (obj_camera) follows the player or other relevant objects around. This has the advantage that it allows control over where the camera goes by just moving the camera object for instance by giving it dynamic movement. It furthermore allows for more smooth camera motion than the build-in functions.
The approach of solely setting up the camera using matric operations does not seem viable anymore.
I found that some of the camera handling I did for GML2 (specifically setting proj. & view matrices directly) would not work properly anymore with any build after V 2.1.4.218 - causing strange flickering effects when using surfaces - even though the camera system worked flawless before.
With any build after 2.1.4.218 whenever I would set the drawing target to any surface GMS2 would start drawing any draw event that came after that line of code in random positions (including tileset layers).
1) DESTROYING CAMERAS
Whenever starting a new room the camera of the previous room will be destroyed using the following script and a new one will be created using the room's properties. The code below is furthermore used in the clean_up event of the camera object to avoid potential memory leaks.
Code:
/// @description destroy camera
/// @argument view_port to reset
var _i = argument[0]; // viewport to reset
view_visible[_i] = false; // disable view visibility
view_enabled = false; // disable view before destroying camera
if (view_camera[_i] != -1) { // if camera assigned destroy and reset
camera_destroy(view_camera[_i]);
view_camera[_i] = -1;
}
show_debug_message("obj_camera: camera destroyed; view_camera[" + string(_i) + "] = " + string(view_camera[_i]) +".");
2) CREATING CAMERAS
The camera object (obj_camera) follows the player or other relevant objects around. This has the advantage that it allows control over where the camera goes by just moving the camera object for instance by giving it dynamic movement. It furthermore allows for more smooth camera motion than the build-in functions.
The approach of solely setting up the camera using matric operations does not seem viable anymore.
Code:
// Setup new camera
view_camera[0] = camera_create_view(0,0,viewWidth, viewHeight, 0, obj_camera, -1, -1, 0.5*viewWidth, 0.5*viewHeight);
view_visible[0] = true;
view_enabled = true;
Last edited by a moderator: