Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

Panel

<Panel slot> stands its children in one of the screen’s nine slots: the four corners, the four edges and the centre. A Panel names a slot and an order, never a position. Each slot stacks its Panels in a column, so two Panels never overlap.

Each side of the screen is one column of three slots, such as Slot.TopRight, Slot.Right and Slot.BottomRight. The middle slot stands centred, and the top and bottom slots share the height it leaves. A stack taller than its share pushes the next slot’s stack along rather than covering it. Only a column taller than the screen runs past its edge, so a game with many buttons on one side lays them out to fit the smallest screen it supports.

Its props are in PanelProps.

A slot Panel sits inside a Hud, which carries it to the screen.

import { Hud, Panel, PanelVariant, Slot, Text } from "@spawnite/engine";
export function Readout({ coins, round }: { coins: number; round: number }) {
return (
<Hud>
<Panel slot={Slot.TopRight} order={1} variant={PanelVariant.Glass}>
<Text>Coins {coins}</Text>
</Panel>
<Panel slot={Slot.TopRight} order={2} variant={PanelVariant.Glass}>
<Text>Round {round}</Text>
</Panel>
</Hud>
);
}

A Panel draws nothing of its own by default, as Godot’s VBoxContainer, Unreal’s VerticalBox and a Roblox Frame with BackgroundTransparency 1 do. The controls in it carry the surface: a Button is glass already, so a row of Buttons stands over the world with no pane behind it.

A readout that stands over the world, such as a score or a line of instructions, asks for a pane with variant={PanelVariant.Glass}, as Unity’s Panel and Godot’s PanelContainer draw a background. The pane draws a Glass behind its content. A single number reads as well in a Counter.

A slot Panel inside an Entity stays in its slot and reads the entity; it does not follow it. That is screen UI, like Unity’s screen-space canvas or Roblox’s ScreenGui. A Panel that follows its entity in the world is anchored.

The Slot members are TopLeft, Top, TopRight, Left, Center, Right, BottomLeft, Bottom and BottomRight.

A Panel stands its children in one centred column. To group them another way, such as two small buttons beside a large one, put a Stack for a column or a Row for a line inside it. Each draws nothing of its own, so a control looks the same in one as out of it.

packages/engine/test/outside/CornerButtons.tsx
import {
Align,
Button,
Gap,
Hud,
Panel,
Row,
Slot,
Stack,
} from "@spawnite/engine";
export function CornerButtons({ onOpen }: { onOpen: (name: string) => void }) {
return (
<Hud>
<Panel slot={Slot.BottomRight}>
{/* A column of two small buttons beside the shop, on its bottom edge. */}
<Row align={Align.End} gap={Gap.Small}>
<Stack align={Align.Stretch} gap={Gap.Small}>
<Button onPress={() => onOpen("tasks")}>Tasks</Button>
<Button onPress={() => onOpen("recipes")}>
Recipes
</Button>
</Stack>
<Button onPress={() => onOpen("shop")}>Shop</Button>
</Row>
</Panel>
</Hud>
);
}

Both take the same three props, each a closed set that also takes its string, such as gap="sm":

  • gap, a Gap, is the space between the children, from None to ExtraLarge. Base, the default, is the Panel’s own gap. A space off the scale is a class, such as className="gap-[0.4em]".
  • align, an Align, is where the children stand across the line: Start, Center, the default, End, Stretch or Baseline. Stretch widens a Stack’s children to its widest, as the sample’s two buttons are.
  • justify, a Justify, is where they stand along it: Start, the default, Center, End, Between, Around or Evenly. It moves them only when the line is longer than they are, such as a Row given a width.

A Stack or a Row that holds nothing, such as a column of buttons that each draw nothing until the player unlocks them, takes no room and no gap. Its props are in StackProps.

Unity’s Vertical and Horizontal Layout Groups, Godot’s VBoxContainer and HBoxContainer, Roblox’s UIListLayout, Unreal’s Vertical and Horizontal Box and SwiftUI’s VStack and HStack do the same.

slot also takes a ResponsiveSlot, one slot for each screen width, so a piece moves on a phone with no width read of your own. The object reads as Chakra UI’s responsive props read, with Tailwind’s default breakpoints: base below sm, and each key from its width up until a wider key the object names.

Key From
base Every width
sm 40rem, 640 px
md 48rem, 768 px
lg 64rem, 1024 px
xl 80rem, 1280 px
2xl 96rem, 1536 px

base is required, so every width has a slot. sm here is the width your game’s sm: and max-sm: classes read, so a class that hides a piece on a phone and a Panel that moves one agree. A game that changes Tailwind’s breakpoints in its CSS keeps these widths for slot.

packages/engine/test/outside/ShopButton.tsx
import { Button, Hud, Panel, Slot } from "@spawnite/engine";
export function ShopButton({ onOpen }: { onOpen: () => void }) {
return (
<Hud>
{/* Under the thumb on a phone, in the right column on a wider screen. */}
<Panel slot={{ base: Slot.BottomRight, sm: Slot.Right }} order={3}>
<Button onPress={onOpen}>Shop</Button>
</Panel>
</Hud>
);
}

The Panel follows the window as it resizes. A move to another slot keeps what the Panel holds, such as a field’s text or a component’s state; a control that has focus loses it in the move. A test or a room with no media queries places the Panel at base.

None of the other engines has a slot per width. Unity anchors a RectTransform and reads Screen.safeArea, Unreal anchors a Canvas Panel’s slots with a Safe Zone, and Godot and PlayCanvas anchor their Controls and Elements. Roblox sizes a frame by Scale and Offset, with ScreenGui.ScreenInsets for the safe area. Each moves a piece by screen size from a script that reads the viewport. The web’s UI libraries make it a value, as Chakra UI’s responsive props and Tailwind’s sm: do, and a Panel takes the same shape.

On a desktop, the engine’s text chat stands in Slot.BottomLeft with its input at the bottom edge, and on a narrow window the input reaches across the bottom row. The bottom slots keep clear of it: each bottom slot whose Panels reach across the input stands its stack above it, and a slot whose Panels stand clear of it stays where it is. The chat stands last in its own slot, so the slot’s other Panels stand above it. On a phone the chat is a button in the corner row, and the slots stay where they are.

The input is what the slots keep clear of. The messages above it, which show while the player reads or types, may cover a Panel for that time. A game that moves its chat with <TextChat slot> to a slot outside the bottom row lifts nothing.

freeCursor frees the cursor while the Panel shows, so a player clicks its controls under a camera that captures the cursor, as in a shooter. The camera takes the cursor back once the Panel goes. Use it for a screen the player stops to click, such as an inventory or a shop, as Roblox’s Modal button does. A readout leaves it off, the default, so it never takes the mouse from the camera. The camera page says what the player sees and how the lock comes back.

import { Button, Hud, Panel, Slot, Text } from "@spawnite/engine";
export function Shop({ onBuy }: { onBuy: () => void }) {
return (
<Hud>
<Panel slot={Slot.Center} freeCursor>
<Text>A sword, 30 coins</Text>
<Button onPress={onBuy}>Buy</Button>
</Panel>
</Hud>
);
}

<Panel anchor> follows the entity it sits in, like Roblox’s BillboardGui. It sits inside an Entity directly, with no Hud, and reads the entity through useEntity(). The screen layer always draws over it, so a nameplate slides under a slot Panel.

Its props are also in PanelProps, and Anchor says where it stands.

For meshes rather than HTML, such as a marker drawn in the scene, a Billboard faces the camera from every side of its entity. A health bar over an entity is a <ResourceBar> in an anchored Panel, as the Health page shows.

An anchored Panel takes the same variant, className and style as a slot Panel; style is for a size that comes from data, never a position, which the slot or the anchor gives. It takes no pointer events itself, so a drag across a nameplate still turns the camera.

import {
Anchor,
Bar,
HealthTrait,
Panel,
Text,
useEntity,
useTrait,
} from "@spawnite/engine";
export function Nameplate() {
const health = useTrait(useEntity(), HealthTrait);
if (!health) return null;
return (
<Panel anchor={Anchor.Above} maxDistance={40}>
<Text>Yeti</Text>
<Bar
label="Yeti health"
value={health.current}
maximum={health.maximum}
/>
</Panel>
);
}