Skip to content

ScreenAnchor

namespace Griff.Scenes;
public sealed class ScreenAnchor : Component

Pins the entity to a point on the screen, for HUDs and menus: a score in the top-left corner stays there whatever the window’s shape, and it doesn’t move when the camera follows the player or shakes. Set while the game runs, after every Update; the entity keeps its Z. With the camera’s HudSize set, it keeps its size on the screen too as the camera zooms.

The camera’s rotation is ignored. The Scene view shows it where the game does on a 16:9 screen, and dragging it there sets its Offset.

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

public Anchor Anchor { get; set; }

The corner, edge or middle of the screen it stays by, at its position from there in world units.

public Vector2 Offset { get; set; }

World units from the anchor point. Right and up are positive, so a top-left score sits at something like (1.5, -0.6).

public static Vector2 Direction(Anchor anchor)

The anchor point, from (-1, -1) bottom left to (1, 1) top right.

public Vector2 PointOn(Vector2 center, Vector2 half, float scale)

The world point it holds its entity at on a view centered on center that reaches half out to its edges, with its offset scale times as long (see HudScale).