Skip to content

Camera

namespace Griff.Scenes;
public sealed class Camera : Component

What the game sees. The entity’s transform positions the camera; rotation and scale apply too.

This is a component: its saved properties are on its component page.

public Color Ambient { get; set; }

The light that reaches everything no Light lights. White (the default) is daylight, where lights make no difference; a dark color makes a cave or a night (dark blue), and black is pitch dark. The HUD and menus are never darkened: anything pinned with a ScreenAnchor, and anything inside the camera.

public Color Background { get; set; }

The color behind everything, where nothing is drawn.

public Color CurrentAmbient { get; }

The ambient light right now: Ambient, or the Ambient of the room the camera is in, fading from one to the other as it moves between rooms.

public float HudScale { get; }

How many times its own size the HUD is drawn so it keeps its size on the screen: Size / HudSize, or 1 with no HudSize.

public float HudSize { get; set; }

The Size the HUD is laid out at, for a camera that zooms: set it (usually to Size) and everything pinned with a ScreenAnchor keeps its size and place on the screen as Size changes, drawn, placed and clicked at Size / HudSize times its size, its anchor’s offset and what’s inside it too. 0 (the default): the HUD is in world units, so it zooms with the world.

public bool IsDark { get; }

True if the ambient light right now (CurrentAmbient) is darker than daylight, so lights show.

public Vector2 KickBy { get; set; }

Which way and how far Kick pushes the view, in world units: (0, -0.3) jolts it down a little, as a landing or a heavy hit does. A Trigger’s or a Button’s Do “Kick” kicks it this way with no code.

public float KickTime { get; set; }

Seconds a kick takes, out and back.

public Vector2 ShakeOffset { get; }

How far the view is currently thrown off by Shake and Kick, in world units.

public float Size { get; set; }

Half the visible height, in world units. Width follows the window’s aspect ratio.

public bool SortByY { get; set; }

For top-down games: among things with the same Order and Z, whatever is lower down draws in front, so the player walks behind a tree’s top and in front of its trunk. A sprite sorts by the bottom of its picture, where it stands (a character’s feet, a tree’s trunk), so tall and short sprites side by side sort by where they stand; anything else that draws sorts by its position. A tilemap that sorts by Y puts each row of tiles at its cells’ middle.

public SceneTransition Transition { get; set; }

How the screen covers up and uncovers a scene change in this scene: a fade, a wipe or an iris.

public void AdvanceShake(float seconds)

Moves the shake and the kick on by seconds and picks this frame’s offset. Called by the game.

public Color AmbientDrawn(StepBlend blend)

The ambient light in a frame drawn as blend says: part way through a fade between steps.

public ValueTuple<float, Color, Vector2> Drawn(StepBlend blend)

Its Size, Background and ShakeOffset in a frame drawn as blend says (see StepBlend).

public void FadeAmbient(Color? ambient, float seconds)

Fades to a room’s ambient light (or back to the camera’s own, with null) over real seconds.

public void Kick()

Kicks the view by its KickBy over its KickTime (see Kick).

public void Kick(Vector2 by, float duration = 0.2f)

Pushes the view a short way by (which way and how far, in world units) and eases it back over duration seconds: a jolt with a direction, where Shake rattles every way. A gun’s recoil kicks it back from where it fires, a landing down. A new kick replaces one in progress. Uses real time, as a shake does, and adds to one.

public void Shake(float strength = 0.3f, float duration = 0.25f)

Shakes the view by up to strength world units, fading out over duration seconds. A stronger shake replaces a weaker one in progress. Uses real time, so it still plays while Scale is 0 (a hit pause).