Viewport
namespace Griff.Scenes;
public sealed class Viewport : ComponentDraws the camera on its entity into part of the screen, over the main camera’s view: a minimap in a corner, one player’s half of a split screen, a first-person window (a camera with a First Person View) inside a 2D game. The part is given as fractions of the screen from its top left, so it keeps its place at any window size; the camera’s own Size is half the view’s height, its width following the part’s shape. Whatever rides inside this camera (its children) is this view’s own HUD, drawn in it and not in the main view; the main view’s HUD (anything with a ScreenAnchor, or inside the main camera) stays on top of every view, with menus and fades.
The main view is the first camera without a viewport; with none, the first camera fills the screen and its viewport draws over it too. A viewport is drawing only: it changes nothing in the game, so rewinds and network games are as ever. Scripts can ask where the mouse is in a view with Game.MouseIn.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Border
Section titled “Border”public Color Border { get; set; }A frame drawn round the view; transparent for none.
Height
Section titled “Height”public float Height { get; set; }How tall the view is, as a fraction of the screen’s height.
IsShowing
Section titled “IsShowing”public bool IsShowing { get; }True if it shows anything: Shown, and some of the screen to show it in.
public float Left { get; set; }Where the view’s left edge is, as a fraction of the screen’s width from its left (0 to 1).
public int Order { get; set; }Which views go over which where they overlap: higher is drawn later, on top.
public bool Shown { get; set; }Shows the view; untick it (or switch it off) to hide it, e.g. a map shown while a key is held. Its camera never becomes the main one.
public float Top { get; set; }Where the view’s top edge is, as a fraction of the screen’s height from its top (0 to 1).
public float Width { get; set; }How wide the view is, as a fraction of the screen’s width: 0.5 for half of a split screen.
Methods
Section titled “Methods”AspectOn
Section titled “AspectOn”public float AspectOn(float screenAspect)The view’s width over its height on a screen screenAspect wide (its width over its height).
ToScreen
Section titled “ToScreen”public Matrix4x4 ToScreen()Takes the view’s clip space (-1..1 across it) to the whole screen’s, onto the part it covers: what a renderer puts after the view’s camera projection.