Game math & UI, rung — panel HUD: a status box that survives a dialog.
Every game needs furniture: a status bar with hearts and a coin count, a dialog box that opens over the world and closes again. Both are the same primitive — a 9-slice panel, a bordered box stamped from a 3x3 tile sheet (four corners, four edges, one fill) onto a background layer. The panel module does the stamping; you own the tilemap.
Its whole point is on show here: the HUD and the dialog live in ONE tilemap on ONE layer. Opening the dialog (panelDraw + panelFlush) and closing it (panelClear + panelFlush) never disturbs the HUD.
panelFlush() uploads the whole 2 KB map under FORCED BLANK, which briefly blanks the screen — fine for a structural change like a dialog box, but far too heavy to run every time a heart changes. So the hearts, which change often, upload only their own 64-byte tilemap row with an ordinary VBlank DMA (flush_hud_row) — no forced blank, no flicker. The rule: panelFlush for structure, a small VBlank DMA for frequent HUD tweaks.
The scene is the noodle bar seen from above (BG1), with Kit at the counter and the raccoon who runs it behind it (sprites). The panel sheet is res/boxes.png, twelve 2bpp tiles in an order the code relies on: tile 0 is left transparent (that is what panelInit() stamps everywhere), so the bar shows through wherever no panel has been drawn; 1-9 are the 9-slice, 10 and 11 the hearts.
The panel layer is BG3, the 2bpp layer of Mode 1 — the usual home of a HUD, cheap in VRAM. In Mode 1, BG3 is drawn behind BG1 and BG2 unless the BGMODE bit BG3_MODE1_PRIORITY_HIGH is set and the BG3 tiles carry their priority bit; then it is in front of everything, sprites included. SELECT turns the bit off and on, and the HUD goes behind the scene and comes back. (That lesson was the mode1_bg3_priority example.)
ROM mode: LoROM (project default).
- Controls
- B: lose a heart · A: gain one (small VBlank DMA of the heart row)
- START: toggle the dialog box — the raccoon talking (panelFlush; the HUD stays put)
- SELECT: BG3_MODE1_PRIORITY_HIGH off / on (the panels behind / in front)
- SNES Concepts
- 9-slice stamping: panelDraw() picks corner/edge/fill from the sheet by position; panelPut() drops a single sheet tile (an icon) into the box
- Several panels, one layer, one upload — the module's reason to exist
- panelFlush() uploads under real forced blank (INIDISP bit 7): safe for 2 KB but it blanks briefly, so use it for structural changes; push a frequently-updated HUD row with a small ordinary VBlank DMA instead
- BG3 in Mode 1: 2bpp tiles (8 words each), 4-colour palettes taken from CGRAM 0-31; in front of BG1/BG2 only with BG3_MODE1_PRIORITY_HIGH and the tile priority bit (Panel.priority = 1)
- What to Observe
- A HUD box with hearts sits over the noodle bar. A/B change the hearts; START opens/closes a dialog box lower down without touching the HUD. SELECT sends both boxes behind the bar (and behind Kit and the raccoon), SELECT again brings them back in front of everything. hero_hp, dialog_shown and bg3_high are the probe oracles.
- Modules Used
- console, dma, background, panel, input, sprite
- See also
- lib/include/snes/panel.h — panelInit/Draw/Put/Clear/Flush