camera_create_view

This function will create a new camera and then set its view into the room, before return the unique ID value to identify the camera in future function calls. The camera will be created using the values that you set in this function for position, size and other details which correlate to the values you set in the Room Editor (see here). Note that this function can take a variable number of arguments with only the x/y position and width/height arguments being obligatory. Any arguments not supplied will use their default arguments.

Note that cameras are like all dynamic resources and will occupy memory when created. This means that you need to take care not to create cameras unnecessarily and to destroy those that you don't need by calling the function camera_destroy(). This also means that cameras will persist from room to room if assigned to a global variable (they will persist when assigned to instance or local variables too, but you can't access them after changing room, hence the memory leak), so that you can - for example - create a new camera, assign it to a global variable, and then at the start of each room use the camera_set_* functions to set the properties before assigning it to a view port.

 

Syntax:

camera_create_view(room_x, room_y, width, height, [angle, object, x_speed, y_speed, x_border, y_border])

ArgumentTypeDescription
room_xRealThe x position (within the room) of the left side of the area the camera view captures.
room_yRealThe y position (within the room) of the top of the area the camera view captures.
widthRealThe width of the area the view captures.
heightRealThe height of the area the view captures.
angleRealOPTIONAL The angle to set the for the camera view(from 0° - 360°, default is 0).
objectObject Asset or Object InstanceOPTIONAL The object ID (or instance ID) for the camera view to follow (default is -1, no object).
x_speedRealOPTIONAL The maximum horizontal speed the view can move at (set to -1 for "instant" following, default is -1).
y_speedRealOPTIONAL The maximum vertical speed the view can move at (set to -1 for "instant" following, default is -1).
x_borderRealOPTIONAL The minimum horizontal space between the edge of the view area and the instance it is set to follow (before the view begins moving and if it is set to follow an instance, default is 0).
y_borderRealOPTIONAL The minimum vertical space between the edge of the view area and the instance it is set to follow (before the view begins moving and if it is set to follow an instance, default is 0).

 

Returns:

Camera ID

 

Example:

camera_destroy(view_camera[0]);
view_camera[0] = camera_create_view(0, 0, 640, 480, 0, obj_Player, 5, 5, -1, -1);

The above code removes the current camera assigned to viewport[0] and then creates a new camera, defines its view properties and then assigns that to viewport[0].