Camera

SplashKit camera functionality allows you to move a virtual camera around in your world.

Splashkit camera functionality allows you to move a virtual camera around in your world. This camera projects to the users window, allowing you to draw things to the screen in your world coordinates.

Camera Guides

Using the Splashkit 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

The position of the camera as a point_2d.

Signatures
point_2d camera_position()
public static Point2D Camera.Position { get }
public static Point2D SplashKit.CameraPosition();
function CameraPosition(): Point2D
def camera_position():
Guides
Using the Splashkit Camera

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

The x location of the camera in game coordinates.

Signatures
double camera_x()
public static double Camera.X { get }
public static double SplashKit.CameraX();
function CameraX(): Double
def camera_x():
Guides
Using the Splashkit Camera

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

The y location of the camera in game coordinates.

Signatures
double camera_y()
public static double Camera.Y { get }
public static double SplashKit.CameraY();
function CameraY(): Double
def camera_y():
Guides
Using the Splashkit Camera

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
Name Type Description
S

Sprite

The sprite to track.

Offset

Vector 2D

The 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)
public static void Camera.CenterCameraOn(Sprite s, Vector2D offset);
public static void SplashKit.CenterCameraOn(Sprite s, Vector2D offset);
procedure CenterCameraOn(s: Sprite; const offset: Vector2D)
def center_camera_on_vector(s, offset):
Guides
Using the Splashkit Camera

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
Name Type Description
S

Sprite

The sprite to track.

Offset X

Double

An additional offset added to the camera, allowing you to position the sprite offset from the center of the screen.

Offset Y

Double

An 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)
public static void Camera.CenterCameraOn(Sprite s, double offsetX, double offsetY);
public static void SplashKit.CenterCameraOn(Sprite s, double offsetX, double offsetY);
procedure CenterCameraOn(s: Sprite; offsetX: Double; offsetY: Double)
def center_camera_on(s, offset_x, offset_y):
Guides
Using the Splashkit Camera

Move Camera By

This function is overloaded. The following versions exist.

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
Name Type Description
Offset

Vector 2D

The amount to move the camera.

Signatures
void move_camera_by(const vector_2d &offset)
public static void Camera.MoveCameraBy(Vector2D offset);
public static void SplashKit.MoveCameraBy(Vector2D offset);
procedure MoveCameraBy(const offset: Vector2D)
def move_camera_by_vector(offset):
Guides
Using the Splashkit Camera

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
Name Type Description
Dx

Double

The amount to move the camera along the x axis.

Dy

Double

The amount to move the camera along the y axis.

Signatures
void move_camera_by(double dx, double dy)
public static void Camera.MoveCameraBy(double dx, double dy);
public static void SplashKit.MoveCameraBy(double dx, double dy);
procedure MoveCameraBy(dx: Double; dy: Double)
def move_camera_by(dx, dy):
Guides
Using the Splashkit Camera

Move Camera To

This function is overloaded. The following versions exist.

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
Name Type Description
Pt

Point 2D

The new camera location

Signatures
void move_camera_to(const point_2d &pt)
public static void Camera.MoveCameraTo(Point2D pt);
public static void SplashKit.MoveCameraTo(Point2D pt);
procedure MoveCameraTo(const pt: Point2D)
def move_camera_to_point(pt):
Guides
Using the Splashkit Camera

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
Name Type Description
X

Double

The new camera x location

Y

Double

The new camera y location

Signatures
void move_camera_to(double x, double y)
public static void Camera.MoveCameraTo(double x, double y);
public static void SplashKit.MoveCameraTo(double x, double y);
procedure MoveCameraTo(x: Double; y: Double)
def move_camera_to(x, y):
Guides
Using the Splashkit Camera

Point In Window

Tests if the point is in the window.

Return Type

Boolean

True if the point is on the screen.

Parameters
Name Type Description
Wind

Window

The window to check

Pt

Point 2D

The point to check.

Signatures
bool point_in_window(window wind, const point_2d &pt)
public static bool Camera.PointInWindow(Window wind, Point2D pt);
public static bool SplashKit.PointInWindow(Window wind, Point2D pt);
function PointInWindow(wind: Window; const pt: Point2D): Boolean
def point_in_window(wind, pt):
Guides
Using the Splashkit Camera

Point On Screen

Tests if the point is on the screen.

Return Type

Boolean

True if the point is on the screen.

Parameters
Name Type Description
Pt

Point 2D

The point to check.

Signatures
bool point_on_screen(const point_2d &pt)
public static bool Camera.PointOnScreen(Point2D pt);
public static bool SplashKit.PointOnScreen(Point2D pt);
function PointOnScreen(const pt: Point2D): Boolean
def point_on_screen(pt):
Guides
Using the Splashkit Camera

Rect In Window

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

Return Type

Boolean

True if any part of the rectangle is in the window.

Parameters
Name Type Description
Wind

Window

The window to check

Rect

Rectangle

The rectangle to check.

Signatures
bool rect_in_window(window wind, const rectangle &rect)
public static bool Camera.RectInWindow(Window wind, Rectangle rect);
public static bool SplashKit.RectInWindow(Window wind, Rectangle rect);
function RectInWindow(wind: Window; const rect: Rectangle): Boolean
def rect_in_window(wind, rect):
Guides
Using the Splashkit Camera

Rect On Screen

Tests if the rectangle is on the screen.

Return Type

Boolean

True if any part of the rectangle is on the screen.

Parameters
Name Type Description
Rect

Rectangle

The rectangle to check.

Signatures
bool rect_on_screen(const rectangle &rect)
public static bool Camera.RectOnScreen(Rectangle rect);
public static bool SplashKit.RectOnScreen(Rectangle rect);
function RectOnScreen(const rect: Rectangle): Boolean
def rect_on_screen(rect):
Guides
Using the Splashkit Camera

Screen Center

Returns the center of the screen in world coordinates.

Return Type

Point 2D

The center of the screen in world coordinates.

Signatures
point_2d screen_center()
public static Point2D Camera.ScreenCenter { get }
public static Point2D SplashKit.ScreenCenter();
function ScreenCenter(): Point2D
def screen_center():
Guides
Using the Splashkit Camera

Screen Rectangle

Returns a rectangle that represents the dimensions of the window.

Return Type

Rectangle

A rectangle representing the dimensions of the current window.

Signatures
rectangle screen_rectangle()
public static Rectangle Camera.ScreenRectangle { get }
public static Rectangle SplashKit.ScreenRectangle();
function ScreenRectangle(): Rectangle
def screen_rectangle():
Guides
Using the Splashkit Camera

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
Name Type Description
Pos

Point 2D

The new location of the camera.

Signatures
void set_camera_position(point_2d pos)
public static void Camera.Position { set }
public static void SplashKit.SetCameraPosition(Point2D pos);
procedure SetCameraPosition(pos: Point2D)
def set_camera_position(pos):
Guides
Using the Splashkit Camera

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
Name Type Description
X

Double

The new x coordinate for the camera

Signatures
void set_camera_x(double x)
public static void Camera.X { set }
public static void SplashKit.SetCameraX(double x);
procedure SetCameraX(x: Double)
def set_camera_x(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
Name Type Description
Y

Double

The new y coordinate for the camera

Signatures
void set_camera_y(double y)
public static void Camera.Y { set }
public static void SplashKit.SetCameraY(double y);
procedure SetCameraY(y: Double)
def set_camera_y(y):

To Screen

This function is overloaded. The following versions exist.

To Screen

Convert the passed in world coordinates to screen coordinates.

Return Type

Point 2D

A point that represents pt in screen coordinates.

Parameters
Name Type Description
Pt

Point 2D

The point to convert - this should be in world coordinates.

Signatures
point_2d to_screen(const point_2d &pt)
public static Point2D Camera.ToScreen(Point2D pt);
public static Point2D SplashKit.ToScreen(Point2D pt);
function ToScreen(const pt: Point2D): Point2D
def to_screen_point(pt):
Guides
Using the Splashkit Camera

To Screen

Convert the rectangle in world coordinates to screen coordinates.

Return Type

Rectangle

A rectangle that represents rect in screen coordinates.

Parameters
Name Type Description
Rect

Rectangle

The rectangle to convert - this should be in world coordinates.

Signatures
rectangle to_screen(const rectangle &rect)
public static Rectangle Camera.ToScreen(Rectangle rect);
public static Rectangle SplashKit.ToScreen(Rectangle rect);
function ToScreen(const rect: Rectangle): Rectangle
def to_screen_rectangle(rect):
Guides
Using the Splashkit Camera

To Screen X

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

Return Type

Double

The x location of the world coordinate on the screen.

Parameters
Name Type Description
World X

Double

The value of the x coordinate to translate to screen.

Signatures
double to_screen_x(double world_x)
public static double Camera.ToScreenX(double worldX);
public static double SplashKit.ToScreenX(double worldX);
function ToScreenX(worldX: Double): Double
def to_screen_x(world_x):
Guides
Using the Splashkit Camera

To Screen Y

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

Return Type

Double

The y location of the world coordinate on the screen.

Parameters
Name Type Description
World Y

Double

The value of the y coordinate to translate to screen.

Signatures
double to_screen_y(double world_y)
public static double Camera.ToScreenY(double worldY);
public static double SplashKit.ToScreenY(double worldY);
function ToScreenY(worldY: Double): Double
def to_screen_y(world_y):
Guides
Using the Splashkit Camera

To World

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

Return Type

Point 2D

The same point in world coordinates.

Parameters
Name Type Description
Pt

Point 2D

The point in screen coordinates.

Signatures
point_2d to_world(const point_2d &pt)
public static Point2D Camera.ToWorld(Point2D pt);
public static Point2D SplashKit.ToWorld(Point2D pt);
function ToWorld(const pt: Point2D): Point2D
def to_world(pt):
Guides
Using the Splashkit Camera

To World X

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

Return Type

Double

The x location of the screen coordinate in the world.

Parameters
Name Type Description
Screen X

Double

The value of the x coordinate on screen to translate to the world.

Signatures
double to_world_x(double screen_x)
public static double Camera.ToWorldX(double screenX);
public static double SplashKit.ToWorldX(double screenX);
function ToWorldX(screenX: Double): Double
def to_world_x(screen_x):
Guides
Using the Splashkit Camera

To World Y

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

Return Type

Double

The y location of the screen coordinate in the world.

Parameters
Name Type Description
Screen Y

Double

The value of the y coordinate on screen to translate to the world.

Signatures
double to_world_y(double screen_y)
public static double Camera.ToWorldY(double screenY);
public static double SplashKit.ToWorldY(double screenY);
function ToWorldY(screenY: Double): Double
def to_world_y(screen_y):
Guides
Using the Splashkit Camera

Vector World To Screen

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

Return Type

Vector 2D

A vector representing the distance and direction points need to move to map from world to screen coordinates.

Signatures
vector_2d vector_world_to_screen()
public static Vector2D Camera.VectorWorldToScreen { get }
public static Vector2D SplashKit.VectorWorldToScreen();
function VectorWorldToScreen(): Vector2D
def vector_world_to_screen():

Window Area

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

Return Type

Rectangle

A rectangle representing the dimensions of the current window.

Parameters
Name Type Description
Wind

Window

The window

Signatures
rectangle window_area(window wind)
public Rectangle Window.Area { get }
public static Rectangle SplashKit.WindowArea(Window wind);
function WindowArea(wind: Window): Rectangle
def window_area(wind):
Guides
Using the Splashkit Camera