Hud2D.component
This package holds more than this page lists. See all of its files in its world.
README.md
Hud2D
The pixel-styled HUD for the twoDKit, plus a live style gallery. It shows a run strip (gems collected / gems in the level, run timer, and the lives left as hearts when Trapline lives are on, or the lives lost when they are not), a "level clear" card with the run's stats and a RUN AGAIN button when the player reaches a goal, a GAME OVER card with TRY AGAIN when Trapline lives run out, and a STYLES panel that switches theme, tile set, background, character, movement feel and camera style while you play, and travels between the scene's levels.
Put it on any scene entity, not on the player. Every peer draws its own HUD for its own player (twoDKit.levels' local player), reading that player's twoDKit.Player2D, the twoDKit.Level2D it is in and the running twoDKit.Camera2D. It needs controlsKit for the Interact control and runs in play mode.
local hud = entity.spawn("Hud")
hud.component.add("twoDKit.Hud2D", { title = "CAVE CLEARED!", accent = "#7fe0ff" })
Fields (local, not synced)
| Field | Default | What |
|---|---|---|
showRun | true | Show the gems / time / lives strip (top-left): hearts for the lives left with PP.player({ lives = n }) (lost ones dimmed; a count past six), else a ✖ count of lives lost. |
showStyles | true | Offer the STYLES button (top-right) and panel. |
title | "" | Title on the level-clear card ("" shows "LEVEL CLEAR!"). |
accent | "#ffd34e" | Accent colour of the pixel style (the other styles bring their own palette). |
style | "pixel" | The HUD's look, applied to the run strip, toasts, cards and STYLES panel: pixel (dark purple, chunky shadows), gameboy (four shades of green), parchment (paper, ink, wax red), neon (glowing cyan and magenta on dark glass), minimal (thin white outlines on clear rounded panels), arcade (one joined CRT bar with scanlines, red captions over chunky yellow digits), wood (carved wooden plaques with grain and nail heads, serif lettering), comic (tilted halftone speech bubbles with tails, thick ink outlines, Anton titles). The list and names are Catalog.hudStyleList / Catalog.hudStyles; PP.hud({ style = "neon" }) sets it. |
HUD moments
- The gem counter bumps, flashes and floats a "+1" whenever this player's
Player2D.gemsgoes up (and on atwoDKit.events"gem" for the local player). - A CHECKPOINT toast slides in at the top for a moment when this player reaches a new checkpoint (Trapline's
checkpointevent, filtered to the local player, or atwoDKit.events"checkpoint").
The style gallery
Open it with the STYLES button or the Interact control. Each row has < and > to cycle:
- THEME, TILE SET, BACKGROUND: applied to every Level2D in the scene, so travelling keeps the look. These are this peer's own view.
- CHARACTER, FEEL: set on this player's Player2D (
setCharacter,setFeel), which syncs, so every peer sees the new character. - CAMERA: sets the Camera2D's
styleand clears every level'scameraoverride. - HUD STYLE: cycles this HUD's
style(this peer's own view). - GO TO: one button per Level2D that has a start marker (
P), named after its entity, minus a trailing "Level": teleports to its start and starts a fresh run. Rooms laid side by side without their own start (a hall of rooms) show as the one room that has it.
RUN AGAIN teleports the player to the current level's start and calls resetRun(). The screen is registered as pp_hud and only re-rendered when something it shows changes.
Game over
When the player's Trapline lives run out (PP.player({ lives = n }) turns lives on), Hud2D dims the world and shows a GAME OVER card: the title drops in letter by letter, then the run's gems, time and lives lost, then a pulsing TRY AGAIN button with the input hint for the device in use (the Jump key on a keyboard, the Jump button on a gamepad, "TAP" on touch). TRY AGAIN, or a fresh press of the Jump control on any device (keyboard, gamepad, touch) once the card has been up for a short beat (0.9 s), calls Trapline's TL.restart (full lives, back at the start, or at the last checkpoint with Course.restartFrom = "checkpoint") and resetRun() on the Player2D. A jump already held when the card appears, or pressed during the beat and still held, does not count. The level-clear card has the same finish (lighter dim, animated title, stats, "ALL GEMS" when every gem was taken, a pulsing RUN AGAIN). Without this card a player out of lives stays dead with no way back. If you also add Trapline's own Trapline.LivesDisplay, set its showGameOver = false so only one game-over screen shows. If Trapline refuses the restart (it only restarts a player on that player's own machine), the card stays up and a warning is logged rather than the HUD resetting a run that did not restart.