ScreenAnchor
namespace Griff.Scenes;
public sealed class ScreenAnchor : ComponentPins 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.
Properties
Section titled “Properties”Anchor
Section titled “Anchor”public Anchor Anchor { get; set; }The corner, edge or middle of the screen it stays by, at its position from there in world units.
Offset
Section titled “Offset”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).
Methods
Section titled “Methods”Direction
Section titled “Direction”public static Vector2 Direction(Anchor anchor)The anchor point, from (-1, -1) bottom left to (1, 1) top right.
PointOn
Section titled “PointOn”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).