On this page

← All documentation

HUD

hud.*: the on-screen elements a mod or a skin adds.

Functions

hud.box

function hud.box(input: BoxNode): string;

Adds a rectangle (background, gradient, border, radius, shadow) and returns its id. Same caller, timing and node rules as hud.text. fill cuts the box horizontally at a fraction, from the left, and the overlay keeps it up to date: songProgress (follows the clock every frame), accuracy, tierShare { tier } (share of the judgements of that tier), playerAccuracy { player } (0 or 1, side-by-side replays).

Every node (box, text, image, group) also takes these fields:

  • visible: hides the node; it adds to showWhen.
  • showWhen: paused, running, showFps (the player's setting), judged (after the first judgement), ghost (a ghost is racing), versus (side-by-side replay), solo (no comparison).
  • animate { on, kind, durationMs }: on is judgement, miss or hit; kind is pop, popFade, popOut or flash; durationMs 1 to 5000. It restarts at each occurrence and scales around the centre of the box. popOut goes from 1.25 to 1 in 140 ms while the opacity falls to 0 over the whole duration, then the node stays hidden.
  • element: ties the node to one HUD element the player can restyle: fps, accuracy, hits, misses, combo, timer, remaining, status, judgement, judgementCounts. The font the player chose for it replaces the node's.
  • layout { x, y, width, height, anchor }: x, y are fractions of the parent's width and height (the screen at the first level) in [-10, 10], ignored inside a flow group; width and height are in [0, 4] as fractions of the screen height; anchor is the point of the node placed at (x, y): topLeft (default), top, topRight, left, center, right, bottomLeft, bottom, bottomRight.
  • style: every length is a fraction of the screen height (0.05 is 54 px at 1080p). Colours are #rgb, #rgba, #rrggbb, #rrggbbaa or theme:<role>. radius, padding, opacity, border.width: [0, 1]; size: (0, 1], 0.04 by default; weight: 100 to 900 in steps of 100; gradient: angle and 2 to 8 stops (at in [0, 1]); shadow: x, y in [-1, 1], blur in [0, 1]; transform: x, y in [-4, 4], scale in [0, 10], rotate in [-3600, 3600] degrees; transitionMs up to 10000; align: start, center, end; italic. shape is plate, control or panel and wins over radius; face is a theme font token (display, body, num, label, mono…) and font wins over it; label: true applies the theme's label look. A value outside its range throws with the reason (for example "style.size must be in (0, 1], got 2").
hud.box({
  id: "bar", fill: { kind: "songProgress" },
  layout: { x: 0.5, y: 0.98, width: 1.2, height: 0.006, anchor: "bottom" },
  style: { background: "#66b3ff" },
});

hud.clear

function hud.clear(input: void): void;

Removes every node of the calling mod (or skin). Call it at game.songStart before rebuilding a HUD that depends on the song.

hud.group

function hud.group(input: GroupNode): string;

Adds a container and returns its id; other nodes join it through their parent. Without flow the children are placed by their own layout. With flow { direction, gap?, align?, justify? } they are laid out in a row or a column: gap in [0, 1] (fraction of the screen height), align start, center, end or stretch, justify start, center, end or spaceBetween. Give the group a width and height if its children use fractions. Groups nest at most 8 levels ("groups nest at most 8 levels deep"); a parent must exist and be a group ("parent x does not exist", "parent x is not a group"); a node cannot be its own parent, and an id already used under another parent is refused ("node x already exists under another parent; remove it to move it"). Children keep their creation order.

hud.group({ id: "row", flow: { direction: "row", gap: 0.01 }, layout: { x: 0.02, y: 0.02 } });
hud.text({ id: "row-hits", parent: "row", text: "0", bind: { kind: "hits" } });
hud.text({ id: "row-misses", parent: "row", text: "0", bind: { kind: "misses" } });

hud.image

function hud.image(input: ImageNode): string;

Adds a PNG and returns its id. src is a relative path to a .png file inside the mod's folder, at most 8 MiB, checked at the call (relative path, real file, PNG signature). fit is contain (default), cover or fill. Same caller, timing, node and style rules as hud.box; the 384-node limit counts it.

hud.image({ id: "logo", src: "logo.png", fit: "contain", layout: { x: 0.02, y: 0.02, width: 0.2, height: 0.1 } });

hud.remove

function hud.remove(input: string): void;

Removes the node and all its descendants. Does nothing if the node does not exist. Mods and skins only, from setup or an event handler.

hud.text

function hud.text(input: TextNode): string;

Adds a text node and returns its id. Mods and skins only: a map script gets "hud.text is not available to map scripts: they only change the playfield". Call it from setup or an event handler, never while the file loads. Each mod owns a retained tree: a node stays until hud.remove, hud.clear or the mod is disabled. Reusing an id replaces the node in place (the parent must be the same). Limits per mod: 384 nodes ("the HUD node limit is 384 per mod"), id of 1 to 64 characters, text of at most 256 characters with no control character except \n and \t.

text is shown outside a play; during a play bind replaces it with a value the overlay updates by itself, without a round trip through the script. Kinds of bind:

  • Counters: combo, maxCombo, hits (judged notes that are not misses), misses, judged, remaining.
  • accuracy, ghostAccuracy, ghostDelta, playerAccuracy, versusGap: decimals 0 to 4, 2 by default.
  • tierCount { tier, digits?, padColor? } and tierName { tier }: tier is an index from 0 to 32. digits (1 to 6) pads the count with zeros (0284); padColor is the colour of those leading zeros (of the whole count while it is 0).
  • lastJudgement { colors? }: the name of the last tier, coloured with its tier colour or with colors (keys are tier ids or indexes, 64 entries at most).
  • lastOffset { decimals?, tinted?, colors?, side? }: signed timing of the last judgement (−12 ms, +8 ms), decimals 0 to 3, side early or late; empty for a miss.
  • pavg: hits of the hardest tier over all judged notes. tierRatio { rank }: the 1:X ratio, rank 0 (hardest tier) or 1.
  • Ghost: ghostCombo, ghostName (empty without a ghost).
  • Side-by-side replays (empty outside a comparison): playerAccuracy, playerCombo, playerHits, playerMisses, playerTierCount { tier }, playerName, playerRate, playerLastJudgement, all with player 0 (left) or 1 (right) (otherwise "must be 0 (left side) or 1 (right side)"); versusGap { metric, decimals? } with metric accuracy, combo or misses (left minus right). The single-play bindings describe the left side only: mark a solo element showWhen: "solo".
  • Time: elapsed, total (m:ss), timer (elapsed / total), fps.
  • label { label }: a translated word, one of hits, misses, combo, accuracy, paused, remaining, fps, early, late, ghost, difference, pauseMenuTitle, pauseMenuContinue, pauseMenuRestart, pauseMenuQuit, pauseMenuVolume, pauseMenuSpeed, kps, kpsMax, gap.
  • action { action }: a native button shown only while the host allows it, one of 18 values: skipIntro; pauseResume, pauseRestart, pauseQuit, pauseVolumeDown, pauseVolumeUp, pauseSwap, pauseSeekBack, pauseSeekForward, pauseSpeedDown, pauseSpeedUp; watchPlayPause, watchSeekBack, watchSeekForward, watchSpeedDown, watchSpeedUp, watchSwap, watchScrub.
hud.text({
  id: "combo", text: "0", bind: { kind: "combo" }, element: "combo",
  animate: { on: "hit", kind: "pop", durationMs: 150 },
  layout: { x: 0.5, y: 0.3, anchor: "center" },
  style: { size: 0.06, align: "center" },
});

hud.update

function hud.update(input: NodePatch): void;

Changes an existing node without recreating it; returns nothing. The node must exist ("node x does not exist"). The given layout and style fields replace those of the node and the others stay. text/bind, src/fit, flow and fill only exist for their node type: on another type the call throws "node x is a box and has no text". It takes the same values and limits as the creation functions. Use it to toggle visible or to change a label from an event handler; values that follow the game (bind, fill) need no update.

hud.update({ id: "combo", visible: false });

Types

Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.

type BoxNode = {
  id: string;
  parent?: string | null;
  fill?: Fill | null;
  visible?: boolean | null;
  layout?: Layout | null;
  style?: Style | null;
  showWhen?: ShowWhen | null;
  animate?: Animate | null;
  element?: HudElement | null;
};

type Fill = { kind: "songProgress"; } | { kind: "accuracy"; } | { kind: "tierShare"; tier: number; } | { kind: "playerAccuracy"; player: number; };

type Layout = {
  x?: number | null;
  y?: number | null;
  width?: number | null;
  height?: number | null;
  anchor?: Anchor | null;
};

type Anchor = "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight";

type Style = {
  color?: string | null;
  background?: string | null;
  gradient?: Gradient | null;
  border?: Border | null;
  radius?: number | null;
  padding?: number | null;
  opacity?: number | null;
  font?: string | null;
  face?: string | null;
  shape?: string | null;
  label?: boolean | null;
  size?: number | null;
  weight?: number | null;
  italic?: boolean | null;
  align?: TextAlign | null;
  shadow?: Shadow | null;
  transform?: Transform | null;
  transitionMs?: number | null;
  easing?: Easing | null;
};

type Gradient = { angle: number; stops: GradientStop[]; };

type GradientStop = { color: string; at: number; };

type Border = { width: number; color: string; };

type TextAlign = "start" | "center" | "end";

type Shadow = {
  x: number;
  y: number;
  blur: number;
  color: string;
};

type Transform = {
  x?: number | null;
  y?: number | null;
  scale?: number | null;
  rotate?: number | null;
};

type ShowWhen = "paused" | "running" | "showFps" | "judged" | "ghost" | "versus" | "solo";

type Animate = {
  on: AnimateOn;
  kind: AnimateKind;
  durationMs: number;
};

type AnimateOn = "judgement" | "miss" | "hit";

type AnimateKind = "pop" | "popFade" | "popOut" | "flash";

type HudElement = "fps" | "accuracy" | "hits" | "misses" | "combo" | "timer" | "remaining" | "status" | "judgement" | "judgementCounts";

type GroupNode = {
  id: string;
  parent?: string | null;
  flow?: Flow | null;
  visible?: boolean | null;
  layout?: Layout | null;
  style?: Style | null;
  showWhen?: ShowWhen | null;
  animate?: Animate | null;
  element?: HudElement | null;
};

type Flow = {
  direction: FlowDirection;
  gap?: number | null;
  align?: FlowAlign | null;
  justify?: FlowJustify | null;
};

type FlowDirection = "row" | "column";

type FlowAlign = "start" | "center" | "end" | "stretch";

type FlowJustify = "start" | "center" | "end" | "spaceBetween";

type ImageNode = {
  id: string;
  parent?: string | null;
  src: string;
  fit?: ImageFit | null;
  visible?: boolean | null;
  layout?: Layout | null;
  style?: Style | null;
  showWhen?: ShowWhen | null;
  animate?: Animate | null;
  element?: HudElement | null;
};

type ImageFit = "contain" | "cover" | "fill";

type TextNode = {
  id: string;
  parent?: string | null;
  text: string;
  bind?: TextBinding | null;
  visible?: boolean | null;
  layout?: Layout | null;
  style?: Style | null;
  showWhen?: ShowWhen | null;
  animate?: Animate | null;
  element?: HudElement | null;
};

type TextBinding = { kind: "combo"; } | { kind: "maxCombo"; } | { kind: "hits"; } | { kind: "misses"; } | { kind: "judged"; } | { kind: "remaining"; } | { kind: "accuracy"; decimals?: number | null; } | { kind: "ghostAccuracy"; decimals?: number | null; } | { kind: "ghostDelta"; decimals?: number | null; } | { kind: "ghostCombo"; } | { kind: "ghostName"; } | { kind: "playerAccuracy"; player: number; decimals?: number | null; } | { kind: "playerCombo"; player: number; } | { kind: "playerHits"; player: number; } | { kind: "playerMisses"; player: number; } | { kind: "playerTierCount"; player: number; tier: number; } | { kind: "playerName"; player: number; } | { kind: "playerRate"; player: number; } | { kind: "playerLastJudgement"; player: number; } | { kind: "versusGap"; metric: VersusMetric; decimals?: number | null; } | { kind: "tierCount"; tier: number; digits?: number | null; padColor?: string | null; roll?: boolean | null; } | { kind: "tierName"; tier: number; } | { kind: "pavg"; } | { kind: "tierRatio"; rank: number; } | { kind: "lastJudgement"; colors?: Record<string, string>; } | { kind: "lastOffset"; decimals?: number | null; tinted?: boolean | null; colors?: Record<string, string>; side?: OffsetSide | null; } | { kind: "elapsed"; } | { kind: "total"; } | { kind: "timer"; } | { kind: "fps"; } | { kind: "label"; label: HudLabel; } | { kind: "action"; action: HudAction; };

type VersusMetric = "accuracy" | "combo" | "misses";

type OffsetSide = "early" | "late";

type HudLabel = "hits" | "misses" | "combo" | "accuracy" | "paused" | "remaining" | "fps" | "early" | "late" | "ghost" | "difference" | "pauseMenuTitle" | "pauseMenuContinue" | "pauseMenuRestart" | "pauseMenuQuit" | "pauseMenuVolume" | "pauseMenuSpeed" | "kps" | "kpsMax" | "nps" | "gap";

type HudAction = "skipIntro" | "pauseResume" | "pauseRestart" | "pauseQuit" | "pauseVolumeDown" | "pauseVolumeUp" | "pauseSwap" | "pauseSeekBack" | "pauseSeekForward" | "pauseSpeedDown" | "pauseSpeedUp" | "watchPlayPause" | "watchSeekBack" | "watchSeekForward" | "watchSpeedDown" | "watchSpeedUp" | "watchSwap" | "watchScrub";

type NodePatch = {
  id: string;
  text?: string | null;
  bind?: TextBinding | null;
  fill?: Fill | null;
  src?: string | null;
  fit?: ImageFit | null;
  flow?: Flow | null;
  visible?: boolean | null;
  layout?: Layout | null;
  style?: Style | null;
  showWhen?: ShowWhen | null;
  animate?: Animate | null;
  element?: HudElement | null;
};

Defined elsewhere

Easing (game)

Source in the game repository: content/mods/sdk/modding.d.ts,content/dev-src/notes/sdk/