Skip to content
Download

Camera

Each room has a camera, set up in the room Inspector. In the code, it is in scene().camera.

Property Type What it is
x, y float Top left corner of the area shown, in world coordinates.
zoom float How much the world is magnified (1 = no zoom). The interface and onRenderGui are not magnified, and mouseX()/mouseY() are already in world coordinates.
bounded bool true = while following a target, the camera doesn’t leave the room. Moved by hand, it isn’t limited.
smoothing float From 0 to 10. 0 sticks to the target; 10 is very smooth.
deadzoneW, deadzoneH float Size of the central rectangle in which the target moves without moving the camera.
Function What it does Example
void follow(Handle<Entity> target) Starts following an instance. The camera centers on it already on the first frame. scene().camera.follow(handle());
void stopFollowing() Stops following; the camera stays where it is. scene().camera.stopFollowing();
void shake(float strength, float seconds) Shakes the screen for seconds seconds, up to strength pixels to each side, weakening until it stops. scene().camera.shake(3, 0.2f);
void onSpawn() override {
scene().camera.follow(handle()); // follow this instance
scene().camera.smoothing = 4;
scene().camera.bounded = true;
}

handle() returns a safe reference to this instance: see Handles.