Skip to content

Viewport

Draws 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 Camera.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.

Requires: Camera

Works with: Follow (to follow a player in their half of the screen)

In a network game, each machine keeps its own entity with this on it: it isn’t sent.

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • left: a number = 0.72. Where the view’s left edge is, as a fraction of the screen’s width from its left (0 to 1). (Field: a number.)
  • top: a number = 0.04. Where the view’s top edge is, as a fraction of the screen’s height from its top (0 to 1). (Field: a number.)
  • width: a number = 0.25. How wide the view is, as a fraction of the screen’s width: 0.5 for half of a split screen. (Field: a number.)
  • height: a number = 0.25. How tall the view is, as a fraction of the screen’s height. (Field: a number.)
  • order: a whole number = 0. Which views go over which where they overlap: higher is drawn later, on top. (Field: a number.)
  • border: a color, “#RRGGBB” or “#RRGGBBAA” = “#F4F4F4C0”. A frame drawn round the view; transparent for none. (Field: a color.)
  • shown: true or false = true. 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. (Field: on or off.)

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • isShowing: true or false. True if it shows anything: Shown, and some of the screen to show it in.

Scripts use it as Viewport: its methods, events and values that aren’t saved with the scene.