On this page

← All documentation

Build a HUD element

Draw text, boxes and images over the game with hud.*: bindings, layout, style, show conditions, animation, images and fonts, with a complete working mod.

The HUD is a tree of nodes that your mod keeps and the game draws in its overlay, above everything else. You describe the nodes once; the overlay updates them. A value that changes at every judgement or every frame (the combo, the accuracy, the song progress) is never written by your script: a binding names it and the overlay fills it in, with no round trip to the mods thread.

Use hud.* for anything that is text, a box or a PNG. If you need effects locked to the frame of the notes (sparks at a hit, a lane glow), use the native stage instead. A skin builds the game's HUD with the same hud.* calls; this page applies to mods and skins alike. It assumes you have made a first mod.

A complete element

This mod draws a panel in the bottom-left corner: a badge and the combo, the accuracy, the last judgement with its timing, a count per hit tier, and a progress bar. The folder also holds badge.png. Nothing in it runs per judgement.

/// <reference path="../../../mods/sdk/modding.d.ts" />

// A panel in the bottom-left corner: a badge and the combo, the accuracy, the last
// judgement with its offset, a count per hit tier, and a song progress bar. Everything
// the panel shows changes through bindings: the overlay updates the texts and the bar
// itself, so no script runs per judgement. The mod only places the nodes, once per play.
//
// Install it by copying this folder into the mods folder (Mods page → Open folder).

/** Screen height fractions: every length of a layout or a style is one. */
const PANEL_WIDTH = 0.42;
const BAR_HEIGHT = 0.008;
const SHADOW = { x: 0, y: 0.002, blur: 0.004, color: "#000000b3" };

function build(tiers: TierInfo[]) {
  hud.clear();

  // The panel: a column group. Its children are placed one under the other, in creation
  // order, so they carry no `x` or `y`. It sits at the bottom-left corner of the screen.
  hud.group({
    id: "panel",
    flow: { direction: "column", gap: 0.006, align: "start" },
    layout: { x: 0.015, y: 0.985, anchor: "bottomLeft" },
    style: { background: "#000000a6", radius: 0.012, padding: 0.012 },
  });

  // A row: the badge (a PNG of the mod's folder) and the combo.
  hud.group({ id: "head", parent: "panel", flow: { direction: "row", gap: 0.01, align: "center" } });
  hud.image({ id: "badge", parent: "head", src: "badge.png", layout: { width: 0.05, height: 0.05 } });
  hud.group({ id: "combo-box", parent: "head", flow: { direction: "column", align: "start" } });
  hud.text({
    id: "combo-label", parent: "combo-box", text: "COMBO", bind: { kind: "label", label: "combo" },
    style: { size: 0.014, color: "theme:text-2", label: true },
  });
  hud.text({
    id: "combo", parent: "combo-box", text: "0", bind: { kind: "combo" },
    // The text is replayed at every hit: a short pop, centered on the node.
    animate: { on: "hit", kind: "pop", durationMs: 140 },
    style: { size: 0.05, weight: 700, color: "theme:text", face: "num", shadow: SHADOW },
  });

  hud.text({
    id: "accuracy", parent: "panel", text: "100.00%", bind: { kind: "accuracy", decimals: 2 },
    style: { size: 0.026, color: "theme:accent", face: "num", shadow: SHADOW },
  });

  // The last judgement takes the color of its tier; it appears after the first one.
  hud.group({ id: "last", parent: "panel", flow: { direction: "row", gap: 0.008, align: "center" }, showWhen: "judged" });
  hud.text({
    id: "judgement", parent: "last", text: "", bind: { kind: "lastJudgement" },
    animate: { on: "judgement", kind: "popOut", durationMs: 700 },
    style: { size: 0.03, weight: 700, shadow: SHADOW },
  });
  hud.text({
    id: "offset", parent: "last", text: "", bind: { kind: "lastOffset", decimals: 0 },
    style: { size: 0.018, face: "num", shadow: SHADOW },
  });

  // One row per hit tier (it has a window; the Miss tier has none), at most four: its
  // translated name and its count, in the tier's color.
  const hitTiers = tiers.filter((tier) => tier.lateMs !== null && tier.lateMs !== undefined).slice(0, 4);
  for (const tier of hitTiers) {
    hud.group({ id: `tier-${tier.index}`, parent: "panel", flow: { direction: "row", gap: 0.008 } });
    hud.text({
      id: `tier-${tier.index}-name`, parent: `tier-${tier.index}`, text: tier.name,
      bind: { kind: "tierName", tier: tier.index }, style: { size: 0.016, color: tier.color },
    });
    hud.text({
      id: `tier-${tier.index}-count`, parent: `tier-${tier.index}`, text: "0",
      bind: { kind: "tierCount", tier: tier.index }, style: { size: 0.016, color: tier.color, face: "num" },
    });
  }

  // The bar: a track and a fill that the overlay clips from the song clock.
  hud.group({ id: "bar", parent: "panel", layout: { width: PANEL_WIDTH, height: BAR_HEIGHT } });
  hud.box({
    id: "track", parent: "bar",
    layout: { x: 0, y: 0, width: PANEL_WIDTH, height: BAR_HEIGHT },
    style: { background: "#ffffff2e", radius: BAR_HEIGHT / 2 },
  });
  hud.box({
    id: "fill", parent: "bar", fill: { kind: "songProgress" },
    layout: { x: 0, y: 0, width: PANEL_WIDTH, height: BAR_HEIGHT },
    style: {
      background: "theme:accent",
      gradient: { angle: 90, stops: [{ color: "theme:accent", at: 0 }, { color: "#ffffff", at: 1 }] },
      radius: BAR_HEIGHT / 2,
    },
  });

  // Shown while the game is paused only.
  hud.text({
    id: "paused", text: "PAUSED", bind: { kind: "label", label: "paused" }, showWhen: "paused",
    layout: { x: 0.5, y: 0.45, anchor: "center" },
    style: { size: 0.06, weight: 700, color: "#ffffff", shadow: SHADOW },
  });
}

export default defineMod({
  id: "example.combo-panel",
  name: "Combo panel",
  version: "1.0.0",
  apiVersion: 2,
  author: "Prism",
  description: "A bottom-left panel: combo, accuracy, last judgement, tier counts and song progress.",
  setup() {
    ctx.on("game.songStart", (start: SongStartEvent) => build(start.judgements.tiers));
    ctx.on("game.songEnd", () => hud.clear());
  },
});

Copy the folder hud-combo-panel into your mods folder (Mods page, Open folder) and start a map. The rest of this page explains each part.

The mod builds its tree at game.songStart and clears it at game.songEnd. That is the convention for a HUD mod: no nodes outside a play, a fresh tree for each play, built from the judgement tiers of the map that starts.

The node tree

A mod owns one tree. Its nodes stay on screen until hud.remove, hud.clear or the mod being disabled. The trees of all mods stack above the skin's tree, in load order.

Function Creates Specific fields
hud.text a text text (required), bind
hud.box a rectangle: background, gradient, border, radius, shadow fill (partly filled from the left)
hud.image a PNG of the mod's folder src (required), fit: contain (default), cover, fill
hud.group a container flow (lays children in a row or a column)

Every node also takes id (required), parent, visible, showWhen, animate, element, layout and style. The creation functions return the id.

Ids and groups

An id is 1 to 64 characters without control characters, unique inside your mod. Only a group can be a parent, and groups nest at most 8 levels deep. Children are drawn in creation order. A node's x and y are fractions of its parent (of the screen at the first level).

Creating a node with an existing id replaces it where it is. The parent must be the same: to move a node, remove it and create it again. Creating an identical node changes nothing, so a rebuild that produces the same tree costs nothing.

Changing and removing nodes

hud.update changes a node you already made. The layout and style fields you give replace those of the node and the others stay. text and bind exist only on a text, src and fit on an image, flow on a group, fill on a box; any other combination throws.

hud.update({ id: "combo", style: { color: "#ffd27a" } });
hud.update({ id: "panel", visible: false });
hud.remove("last");
hud.clear();

hud.remove deletes the node and all its descendants and ignores an unknown id. hud.update of an unknown id throws.

Rebuilding the whole element when its options change (hud.remove of the root, then the creation calls) is the simplest approach and what the shipped mods do. It is cheap: unchanged nodes publish nothing.

Text and bindings

text is shown outside a play and while no binding gives a value. During a play a bind replaces it. The overlay resolves and formats every binding itself, on the frame the value changes.

Bindings for one play

bind.kind Shows
combo, maxCombo the combo, the highest combo of the play
hits judged notes that are not misses
misses the count of the Miss tier (the last tier)
judged, remaining notes judged so far, notes not judged yet
accuracy the accuracy as a localized percentage; decimals 0 to 4, 2 by default
tierCount {tier, digits?, padColor?}, tierName {tier} the count and the translated name of the tier at index tier (0 to 32). digits (1 to 6) pads the count with zeros, like 0284; padColor colors those leading zeros (the whole count while it is 0)
lastJudgement {colors?} the name of the last tier judged, in that tier's color, or in the color colors gives its id or its index ({ "perfect": "#fff", "3": "#4fc3f7" }, 64 entries at most)
lastOffset {decimals?, tinted?, colors?, side?} the signed timing of the last judgement, like -12 ms (early) or +8 ms (late). decimals 0 to 3, 0 by default. Empty before the first judgement and for a miss. The node takes the tier's color unless tinted is false. side shows only the early or only the late timings, so two nodes put the timing on the side of its sign
elapsed, total, timer the song time m:ss, the duration, elapsed / total
fps the game's frames per second
pavg, tierRatio {rank} PAvg, and the ratio 1:X of the hardest (rank 0) or second hardest (rank 1) hit tier
label {label} a word translated into the player's language: hits, misses, combo, accuracy, paused, remaining, fps, early, late, ghost, difference, kps, kpsMax, gap, and the pause menu words pauseMenuTitle, pauseMenuContinue, pauseMenuRestart, pauseMenuQuit, pauseMenuVolume, pauseMenuSpeed
action {action} a native button, visible only while the game allows its action (skipIntro, the pause* and watch* actions). You choose the look; the game does the action
hud.text({ id: "acc", text: "", bind: { kind: "accuracy", decimals: 1 } });
hud.text({ id: "early", text: "", bind: { kind: "lastOffset", side: "early" } });
hud.text({ id: "late", text: "", bind: { kind: "lastOffset", side: "late" } });

Comparison and ghost bindings

Two modes give a play extra data. In a side-by-side comparison of two replays, the single-play bindings above describe the left side only. The player* bindings take a player (0 left, 1 right): playerAccuracy, playerCombo, playerHits, playerMisses, playerName, playerRate, playerLastJudgement and playerTierCount (with tier). versusGap {metric, decimals?} shows how far the left side is ahead (accuracy, combo or misses). They are empty outside a comparison.

Against a ghost, ghostAccuracy, ghostDelta (your accuracy minus the ghost's, in points), ghostCombo and ghostName show the ghost; they are empty without one. Use showWhen to show or hide what depends on the mode (see Showing and hiding).

Fill of a box

fill cuts a box horizontally at a fraction, from its left edge, following a game value: { kind: "songProgress" } (the song clock, every frame), { kind: "accuracy" }, { kind: "tierShare", tier } (the share of judgements in that tier) and { kind: "playerAccuracy", player } in a comparison. A bar growing from the right is the same box rotated by half a turn with style.transform: { rotate: 180 }.

Layout, anchors and units

layout is { x?, y?, width?, height?, anchor? }.

Field Meaning Range
x, y position as a fraction of the parent's width and height; (0, 0) is the top left. Ignored inside a flow group -10 to 10
width, height size, as a fraction of the screen height 0 to 4
anchor the point of the node placed at (x, y): topLeft (default), top, topRight, left, center, right, bottomLeft, bottom, bottomRight

Every length in layout sizes and in style is a fraction of the screen height, so an element keeps its proportions in any aspect ratio. At 1920x1080, 0.05 is 54 px; a bar across a 16:9 screen is about 1.73 wide. Without width and height a node takes the size of its content. Give a size to a group whose children are placed with fractions.

A flow group lays its children out one after another: { direction: "row" | "column", gap?, align?, justify? }. gap is 0 to 1; align (across) is start, center, end or stretch; justify (along) is start, center, end or spaceBetween.

An invalid layout value throws in your script:

hud.text({ id: "title", text: "Hello", layout: { x: 0.5, y: 0.1, anchor: "middle" } });

Style

style maps each property to one CSS property of the overlay. Every field is optional.

Property Values Effect
color a color text color; white by default
background a color fill of a box or group
gradient { angle, stops: [{ color, at }] }; 2 to 8 stops, at 0 to 1; angle in degrees, 0 up and 90 to the right linear gradient over background
border { width, color }; width 0 to 1 solid border
radius, padding 0 to 1 corner radius, inner spacing
shape plate, control, panel the theme's shape (its clipped corners, the smaller clip of its buttons, its panel radius); wins over radius
opacity 0 to 1 opacity
font a font name see Fonts
face a theme font face: display, body, num, label, mono the active theme's font; font wins if both are set
size above 0, up to 1; 0.04 by default font size (line height)
weight 100 to 900 by steps of 100 font weight
label boolean the theme's label look: its letter case and spacing, and its label weight unless weight is set
italic boolean italic
align start, center, end text alignment
shadow { x, y, blur, color }; x, y in -1 to 1, blur 0 to 1 text shadow on a text, box shadow otherwise
transform { x?, y?, scale?, rotate? }; translation -4 to 4, scale 0 to 10, rotate in degrees -3600 to 3600 applied after layout, around the anchor
transitionMs 0 to 10000 duration of the transition between two values

Colors and the theme

A color is #rgb, #rgba, #rrggbb or #rrggbbaa (sRGB, straight alpha), or theme:<role>. A role is a colour token of the active interface theme: theme:text, theme:text-2, theme:plate, theme:accent, theme:line, theme:ok, theme:danger, and so on. A role follows the theme when the player changes it, so prefer roles to hex values for the text and surfaces of an element. A name that is not a colour token is refused.

hud.text({
  id: "score", text: "0",
  style: { color: "theme:text", face: "num", shadow: { x: 0, y: 0.002, blur: 0.004, color: "#000000b3" } },
});

face is checked as a theme font token (font-<face>), so it is not limited to five names. An explicit font wins.

Showing and hiding

A node is drawn when visible is not false and its showWhen holds. Change visible with hud.update; use showWhen for what depends on the state of the play, with no script call.

showWhen The node is drawn
running while the play runs, not paused
paused while the play is paused
judged after the first judgement of the play
showFps when the player's "show FPS" setting is on
ghost while the play has a ghost
versus during a side-by-side comparison of two replays
solo outside a comparison; use it on elements built for one play, since a comparison gives each side its own player* bindings

Animation

animate: { on, kind, durationMs } restarts an animation on the node each time on happens: judgement (every judgement), hit (a judgement in a hit tier) or miss (a judgement in the Miss tier). durationMs is 1 to 5000.

kind Effect
pop the scale goes from 1.35 to 1 and the opacity from 0.4 to 1, then the node is back at rest
popFade the same pop in the first fifth, then the opacity falls to 0.35 over the end of the duration and stays there
popOut the scale goes from 1.25 to 1 in 140 ms, whatever the duration, while the opacity falls linearly from 1 to 0 over the whole duration; then the node stays hidden
flash the opacity goes from 0 to 1 and back to 0

The scale turns around the center of the node, whatever its anchor, and adds to the node's own transform. With the system's "reduce motion" preference the overlay keeps the fades and drops the scaling.

Images and fonts

Images

hud.image({ src }) takes the path of a .png inside the mod's folder: relative, a real file in the folder (links and junctions are followed and must stay inside it), with a PNG signature, at most 8 MiB. The path is checked at the call. The overlay asks the game for the file, which checks it again before serving it. fit is contain (default), cover or fill.

Fonts

Declare the fonts of the mod in defineMod, then use their names in style.font.

/// <reference path="../../../mods/sdk/modding.d.ts" />

export default defineMod({
  id: "example.big-score",
  name: "Big score",
  version: "1.0.0",
  apiVersion: 2,
  fonts: { title: "fonts/Title-Bold.ttf" },
  setup() {
    ctx.on("game.songStart", () => {
      hud.text({
        id: "title", text: "0", bind: { kind: "combo" },
        layout: { x: 0.5, y: 0.1, anchor: "top" },
        style: { font: "title", size: 0.08 },
      });
    });
    ctx.on("game.songEnd", () => hud.clear());
  },
});
  • A font is a .ttf or .otf file inside the mod's folder, with a TrueType or OpenType signature, at most 8 MiB. A mod declares at most 8.
  • The name is 1 to 64 characters among ASCII letters and digits, space, -, _ and ., with no space at either end.
  • An invalid font stops the mod from loading: font `title`: ….
  • style.font with a declared name selects the mod's font; it is published as the family <mod id>/<name> and shadows a global font of the same name for this mod only. "<package>/<font>" names a font another package provides, passed through as is: an element that others configure can take its user's font this way. Any other name is global ("default" is the game's font, or a font the player installed).
  • The overlay uses the game's font for a family it does not have.

An element others can configure

A mod can expose its HUD as an element: it declares options in provides.elements, and a skin, another mod or the player places and colors it without a line of your code being called. This is how every widget of the default HUD is built. The pattern, the option kinds and the layers of configuration are in Configurable elements, settings and storage.

Give each node of such an element the element field when it is one of the game's known elements: fps, accuracy, hits, misses, combo, timer, remaining, status, judgement or judgementCounts. The font the player chose for that element (the hudFonts setting) then replaces the font of the node and of its descendants.

Limits

What Limit
Nodes per mod 384
Text length 256 characters; no control character other than \n and \t
id length 1 to 64 characters, no control character
Group depth 8 levels
layout.x, layout.y -10 to 10
layout.width, layout.height 0 to 4
style.size above 0, up to 1
radius, padding, border.width, flow.gap 0 to 1
shadow offsets / blur -1 to 1 / 0 to 1
transform translation / scale / rotate -4 to 4 / 0 to 10 / -3600 to 3600
transitionMs 0 to 10000
Gradient stops 2 to 8
animate.durationMs 1 to 5000
decimals 0 to 4 (0 to 3 for lastOffset)
Tier index 0 to 32
colors of a binding 64 entries, keys of 1 to 32 characters
PNG 8 MiB
Fonts 8 per mod, 8 MiB each

A map script cannot use hud.* at all.

Errors you will see

A value out of bounds, an unknown field or an unreadable color throws a TypeError with the reason in your script. You can catch it. An error that escapes a handler is logged on the Mods page; three in a row, or three calls over the 30 ms budget, disable the mod until the game restarts.

try {
  hud.update({ id: "combo", style: { size: 2 } });
} catch (error) {
  log.warn(`HUD: ${error}`);
}
Message Cause
style.size must be in (0, 1], got 2 a number out of its range (the name is the field's path)
style.color must be #rgb, #rgba, #rrggbb, #rrggbbaa or a colour theme role, got "red" a color that is not hex or a theme role
style.color must name a colour theme role as theme:<role>, got "theme:nope" an unknown role
style.shape must be plate, control or panel, got "round" an unknown shape
the HUD node limit is 384 per mod too many nodes: rebuild instead of piling up
node `x` already exists under another parent; remove it to move it same id, new parent
parent `p` does not exist / parent `p` is not a group the parent must exist first and be a group
groups nest at most 8 levels deep a tree too deep
node id must have 1 to 64 characters, without control characters an invalid id
text has 300 characters, the limit is 256 a text too long
node `x` is a text and has no `src` a hud.update field that does not fit the node's kind
node `x` does not exist hud.update of an unknown id
bind.tier must be a tier index from 0 to 32, got 40 a tier index out of range
"badge.png" is not a PNG image / "badge.png" must be a .png file src does not name a real PNG
`hud.text` is not available while the mod loads: call it from `setup` or an event handler a hud.* call at the top level of main.ts
`hud.text` is not available to map scripts: they only change the playfield hud.* in a map script

Pitfalls

  • Do not update a binding's value yourself. A hud.update({ text }) per judgement costs a round trip through the mods thread and lags behind; bind it.
  • Build in game.songStart, not at load. The tiers, the keys and the playfield are those of the map that starts; a skin or a map can change them between plays.
  • Clear in game.songEnd, or the nodes stay on the result screen.
  • visible: false hides a node but keeps it counted in the 384. Remove what you do not need.
  • A length written as a pixel count is wrong: a size is a fraction of the screen height. size: 54 throws.
  • A hud.update of layout or style merges field by field. To drop a field, rebuild the node.
  • x and y do nothing for a child of a flow group. Move the group.
  • Colors in hex do not follow the theme. Use theme:<role> for text and surfaces.
  • Time and randomness are not deterministic in a mod. Take every value from events and bindings.

See also

Source in the game repository: crates/modding/src/scene.rs,crates/modding/src/api.rs,crates/modding/src/fonts.rs,crates/modding/src/assets.rs,content/examples/mods/hud-combo-panel/main.ts,content/mods/combo/main.ts,content/mods/progress-bar/main.ts,content/mods/judgement-display/main.ts,content/mods/sdk/modding.d.ts