Skip to content

Camera

Functions

Camera Position

Returns the position of the camera in game coordinates. This will be the coordinate of the upper left corner of the screen.

Return Type: Point 2d

Signatures:

point_2d camera_position()

Camera X

Returns the x location of the camera in game coordinates. This represents the left most x value shown on the screen, with the right of the screen being at camera x + screen width.

Return Type: Double

Signatures:

double camera_x()

Camera Y

Returns the y location of the camera in game coordinates. This represents the stop most y value shown on the screen, with bottom of screen being at camera y + screen height.

Return Type: Double

Signatures:

double camera_y()

Center Camera On

Center Camera On

Set the camera view to be centered over the specific sprite. The offset vector allows you to move the sprite from the direct center of the screen.

Parameters:

NameTypeDescription
sSpriteThe sprite to track.
offsetVector 2dThe amount to offset the camera, allowing you to position the sprite away from the center of the screen.

Signatures:

void center_camera_on(sprite s, const vector_2d &offset)

Center Camera On

Set the camera view to be centered over the specific sprite. The offset vector allows you to move the sprite from the direct center of the screen.

Parameters:

NameTypeDescription
sSpriteThe sprite to track.
offset_xDoubleAn additional offset added to the camera, allowing you to position the sprite offset from the center of the screen.
offset_yDoubleAn additional offset added to the camera, allowing you to position the sprite offset from the center of the screen.

Signatures:

void center_camera_on(sprite s, double offset_x, double offset_y)

Move Camera By

Move Camera By

Move the camera (offset its world x and y values) using the specified vector. For example, if you move the camera by the same speed vector of a sprite the camera will “track” (be locked on to) the sprite as it moves.

Parameters:

NameTypeDescription
offsetVector 2dThe amount to move the camera.

Signatures:

void move_camera_by(const vector_2d &offset)

Move Camera By

Move the camera (offset its world x and y values) using the specified dx (change in x) and dy (change in x) values.

Parameters:

NameTypeDescription
dxDoubleThe amount to move the camera along the x axis.
dyDoubleThe amount to move the camera along the y axis.

Signatures:

void move_camera_by(double dx, double dy)

Move Camera To

Move Camera To

Move the camera view (screen top left) to a specified point in the world. This will be the new top left corner of the screen.

Parameters:

NameTypeDescription
ptPoint 2dThe new camera location

Signatures:

void move_camera_to(const point_2d &pt)

Move Camera To

Move the camera view to a world location specified by the x and y values. This will be the new top left corner of the screen.

Parameters:

NameTypeDescription
xDoubleThe new camera x location
yDoubleThe new camera y location

Signatures:

void move_camera_to(double x, double y)

Point In Window

Tests if the point is in the window.

Parameters:

NameTypeDescription
windWindowThe window to check
ptPoint 2dThe point to check.

Return Type: Boolean

Signatures:

bool point_in_window(window wind, const point_2d &pt)

Point On Screen

Tests if the point is on the screen.

Parameters:

NameTypeDescription
ptPoint 2dThe point to check.

Return Type: Boolean

Signatures:

bool point_on_screen(const point_2d &pt)

Rect In Window

Tests if the rectangle is within the bounds of the window.

Parameters:

NameTypeDescription
windWindowThe window to check
rectRectangleThe rectangle to check.

Return Type: Boolean

Signatures:

bool rect_in_window(window wind, const rectangle &rect)

Rect On Screen

Tests if the rectangle is on the screen.

Parameters:

NameTypeDescription
rectRectangleThe rectangle to check.

Return Type: Boolean

Signatures:

bool rect_on_screen(const rectangle &rect)

Screen Center

Returns the center of the screen in world coordinates.

Return Type: Point 2d

Signatures:

point_2d screen_center()

Screen Rectangle

Returns a rectangle that represents the dimensions of the window.

Return Type: Rectangle

Signatures:

rectangle screen_rectangle()

Set Camera Position

Change the position of the camera to a specified world coordinate. This will then be the new top left most position of the screen within the world.

Parameters:

NameTypeDescription
posPoint 2dThe new location of the camera.

Signatures:

void set_camera_position(point_2d pos)

Set Camera X

Change the X position of the camera to a specified world coordinate. This will then be the new left most position of the screen within the world.

Parameters:

NameTypeDescription
xDoubleThe new x coordinate for the camera

Signatures:

void set_camera_x(double x)

Set Camera Y

Change the Y position of the camera to a specified world coordinate. This will then be the new top most position of the screen within the world.

Parameters:

NameTypeDescription
yDoubleThe new y coordinate for the camera

Signatures:

void set_camera_y(double y)

To Screen

To Screen

Convert the passed in world coordinates to screen coordinates.

Parameters:

NameTypeDescription
ptPoint 2dThe point to convert - this should be in world coordinates.

Return Type: Point 2d

Signatures:

point_2d to_screen(const point_2d &pt)

To Screen

Convert the rectangle in world coordinates to screen coordinates.

Parameters:

NameTypeDescription
rectRectangleThe rectangle to convert - this should be in world coordinates.

Return Type: Rectangle

Signatures:

rectangle to_screen(const rectangle &rect)

To Screen X

Translate a world x value to the current screen x value which is based on the camera position.

Parameters:

NameTypeDescription
world_xDoubleThe value of the x coordinate to translate to screen.

Return Type: Double

Signatures:

double to_screen_x(double world_x)

To Screen Y

Translate a world y value to the current screen y value set by the camera.

Parameters:

NameTypeDescription
world_yDoubleThe value of the y coordinate to translate to screen.

Return Type: Double

Signatures:

double to_screen_y(double world_y)

To World

Converts the passed in point from screen coordinates to world coordinates.

Parameters:

NameTypeDescription
ptPoint 2dThe point in screen coordinates.

Return Type: Point 2d

Signatures:

point_2d to_world(const point_2d &pt)

To World X

Translate a screen x value (based on the camera) to a world x value

Parameters:

NameTypeDescription
screen_xDoubleThe value of the x coordinate on screen to translate to the world.

Return Type: Double

Signatures:

double to_world_x(double screen_x)

To World Y

Translate a screen y value (based on the camera) to a world y value

Parameters:

NameTypeDescription
screen_yDoubleThe value of the y coordinate on screen to translate to the world.

Return Type: Double

Signatures:

double to_world_y(double screen_y)

Vector World To Screen

Returns a vector that can transform points from world to screen coordinates.

Return Type: Vector 2d

Signatures:

vector_2d vector_world_to_screen()

Window Area

Returns a rectangle that represents the dimensions of the window based on the camera.

Parameters:

NameTypeDescription
windWindowThe window

Return Type: Rectangle

Signatures:

rectangle window_area(window wind)