Skip to content

EdgePointer

namespace Griff.Scenes;
public sealed class EdgePointer : Component

Points the way to something off the screen, as a strategy game’s objective marker does: while its Target is out of the camera’s view, the entity sits on the screen’s edge (in by Margin) where the line from the screen’s middle to the target crosses it, turned to point at the target, and slides along the edge as the camera pans or zooms. Once the target is in view it hides, or sits over the target (see InView). Draw its sprite pointing right. A Button on it whose Do is “Glide” glides the camera there on a click; a Text inside it showing its Distance output (“{0:0} m”) says how far off the target is, and stays upright.

It’s pinned to the main camera’s screen as a ScreenAnchor is, laid out after them each frame, and keeps its size as the camera zooms with the camera’s HudSize and the player’s UI Scale. Its target goes by its position. It decides whether its entity is shown, so to hide it some other way, hide what it’s inside. The Scene view shows it where it’s placed; it only moves while the game runs.

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

public float Distance { get; }

How far the target is from the middle of the screen, in world units: a Text inside it can show it (“{0:0} m”).

public EdgePointerInView InView { get; set; }

What it does while the target is in view: hide (the default), or sit over the target pointing down at it.

public bool IsOnEdge { get; }

True while the target is out of view and it’s on the screen’s edge pointing at it.

public float Margin { get; set; }

How far in from the screen’s edges it sits, in world units of the HUD (as a ScreenAnchor’s Offset is): room for half of it, and for a bar along the edge.

public Vector2 OverTarget { get; set; }

Where it sits from the target while that’s in view, in world units: (0, 1) just over a worker’s head. Past the screen’s edge it stays on the edge.

public string? Target { get; set; }

The name of the entity to point at, e.g. “Goal” (found as names find entities). A script, or a Trigger’s Point At, changes it as the goal moves on; empty points at nothing, and it hides.

public Entity? TargetEntity { get; set; }

The entity it points at. Set it from a script to point at something without naming it; it holds until Target changes.

public static Vector2? EdgePoint(Vector2 center, Vector2 reach, Vector2 target)

Where it sits to point at target on a view centered on center that reaches reach out to its edges (less its margin): where the line from the middle to the target crosses the edge, or null while the target is inside.

public void Glide()

Glides the camera over to the target with its CameraControls (see GlideTo) and leaves it the player’s there: what a Button on it does with Do set to Glide. Nothing happens without a target, or without Camera Controls on the camera.

public void PointAt(string? name)

Points at the entity with this name from now on: a Trigger or a script moving the goal on. Empty points at nothing.

public override string? SetupNote()