Camera

The camera is a simple 2D camera that uses orthographic projection under the hood. You can use the camera to adjust the position of the game world, convert screen coordinates to world coordinates, zoom in and zoom out by setting the scale of the camera, and more.

The user cannot current create there own instance of the camera; however, they can access the main camera and use the functions provided.

The camera is basically a Rect that will show what is inside of it. It has a position, scale, width, and height.

TODO: Eventually, all games will have a settings file to allow the creator to adjust the camera width/height, along with the window width for each game. That is currently under construction.

Functions:

FunctionDescription
get()The get function will return an reference to the camera.
position()This will return the current position of the top left corner or the camera.
set_position(vec2)In order to move the camera, the user must set the position of the camera. It takes in a vec2 for the new position.
scale()This will return the current scale of the camera. The scale is a float value. Default scale is 1.0
set_scale(float)This will set the new scale of the camera. It will allow the user to zoom in and out.
width()This will return the current width of the camera. The width of the camera is set based on the width of the window when the game is created.
height()This will return the current height of the camera. The height of the camera is set based on the height of the window when the game is created.

Examples

Move Camera Position

	-- Get an instance of the camera
	local cam = Camera.get()
	
	-- Get the camera position, since it does not have a ctor
	-- we use the '.' operator rather than the ':'.
	local cam_pos = cam.position()

	-- Move the camera in the x direction on every update
	cam.set_position(vec2(cam_pos.x + 10, cam_pos.y))

Set Camera Scale

	-- Get an instance of the camera
	local cam = Camera.get()
	
	-- Set the camera scale to 4. This will zoom in by 4x. 
	-- So if the sprite is 16x16px, it will now look 64x64px.
	cam.set_scale(4.0)

These functions will control the main camera. If you want to use the camera to follow a specific player or entity, try to make use of the Follow Camera or create a lua class that will control the camera any way you see fit.