On this page

← All documentation

Native drawing (stage)

stage.*: sprites, shapes and animations drawn by the renderer (permission stage).

Functions

stage.clear

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

Removes every element, emitter and trigger of the calling script. Call it at game.songStart before rebuilding the scene. Same permission rules as stage.sprite; the player removing the permission clears the scene at once.

stage.emitter

function stage.emitter(input: StageEmitter): string;

Creates a particle emitter and returns its id. Same permission, timing, at, layer and budget rules as stage.sprite. size is the particle size, lifetimeMs its life (at most 5000 ms), maxParticles the cap of live particles (at most 512 per emitter; the sum over the script is capped at 1024). burst particles come out each time the emitter receives the burst cue (at most 256), rate per second continuously. speed, speedJitter, direction, spread (degrees), gravity (within ±16) shape the motion; color fades to endColor; fade and shrink end the life smoothly; image draws a declared PNG instead of a square. An emitter on a lane or receptor position with no column projects its particles onto the column of the event that triggers it. When full, the oldest particle is replaced.

stage.emitter({
  id: "sparks", at: { space: "receptor" }, size: 0.008, color: "#ffd24a",
  lifetimeMs: 380, speed: 0.55, spread: 150, gravity: 1.6, burst: 14, maxParticles: 120,
});
stage.trigger({ id: "hit", on: { judgement: { tier: 0 } }, target: "sparks", play: "burst" });

stage.play

function stage.play(input: StageCue): void;

Starts an animation of an element (target, animation) from the next frame, for example from an event handler. Same permission and timing rules as stage.sprite. Throws if the element does not exist or lacks that animation. At most 64 cues are queued; past that the oldest is dropped.

stage.play({ target: "glow", animation: "flash" });

stage.rect

function stage.rect(input: StageRect): string;

Draws a filled rectangle and returns its id. Same permission, timing, at, layer, animation and budget rules as stage.sprite; no image is needed. radius rounds the corners in screen heights (half the short side makes a circle or a pill).

stage.rect({ id: "bar", at: { space: "screen", x: 0.5, y: 0.9 }, size: { width: 0.4, height: 0.01 }, color: "#66b3ff", radius: 0.005 });

stage.remove

function stage.remove(input: string): boolean;

Removes the element or trigger with that id and returns true if there was one, false otherwise. Same permission and timing rules as stage.sprite.

stage.sprite

function stage.sprite(input: StageSprite): string;

Draws a PNG image in the game's native renderer, in the same frame as the notes, and returns its id. It needs permissions: ["stage"] in defineMod, defineSkin or defineChart (map scripts may draw too): without it the call throws "stage.sprite needs the stage permission: declare permissions: [\"stage\"]", and if the player turned native drawing off for the mod: "stage.sprite: the player turned off native drawing for <id>". image must be one of the images the script declared (64 at most): "image "x" is not declared in images: only declared images are loaded". Call it from setup or an event handler; a scene built in setup comes back after a reload, one built at game.songStart at the next play.

Every stage element has an id (1 to 64 characters; recreating it replaces it in place, keeping running animations and particles) and these shared fields:

  • at { space?, column?, x?, y? }: screen (default; origin top left, x and y are fractions of the width and height), or playfield (centre of the columns' box), lane (centre of column), receptor (receptor of column), where x and y are screen heights, right and down. lane and receptor need a column (below 32). Every space other than screen follows the playfield when a map script moves it.
  • layer: below (behind the playfield), lanes (over the columns, under the notes), above (default, over the notes). All sit under the HUD.
  • size { width, height } from 0 to 4 screen heights; opacity 0 to 1; scale 0 to 16; rotation in degrees; color #rgb to #rrggbbaa; offsets within ±4.
  • animations: up to 8 named animations { durationMs, easing?, repeat?, from?, to? }, each at most 10 s; from and to set x, y (screen-height offsets), scale, rotation, opacity, color. Missing values stay the element's own and return when the animation ends. burst is a reserved name. Run them with stage.trigger, stage.play or stage.stop.

Budgets per script: 128 elements, 16 emitters, 1024 live particles, 64 triggers; past them the call throws, for example "the stage holds 128 elements, its limit". Out-of-range values throw "name: value is outside [min, max]".

stage.sprite({
  id: "glow", image: "glow.png", at: { space: "receptor", column: 0 },
  size: { width: 0.12, height: 0.12 }, opacity: 0,
  animations: { flash: { durationMs: 200, from: { opacity: 1 }, to: { opacity: 0 } } },
});

stage.stop

function stage.stop(input: StageCue): void;

Stops a running animation of an element (target, animation); the element returns to its own values. Same rules and errors as stage.play; this is how a repeat animation ends.

stage.text

function stage.text(input: StageText): string;

Draws one line of text in the game's font and returns its id. Same permission, timing and rules as stage.sprite. text holds at most 128 characters ("text: longer than 128 characters"); size is the line height in screen heights (> 0); align is start, center or end.

stage.text({ id: "title", at: { space: "screen", x: 0.5, y: 0.1 }, text: "Go!", size: 0.05, align: "center" });

stage.trigger

function stage.trigger(input: StageTrigger): string;

Registers a rule evaluated by the renderer every frame (nothing runs in the script). on has exactly one field: judgement { tier?, column?, miss? }, press { column? }, release { column? }, holdStart { column? } or holdEnd { column? }; absent filters match everything ("on needs exactly one of judgement, press, release, holdStart and holdEnd"). Give exactly one of play or stop (an animation name, or burst for an emitter): "a trigger needs exactly one of play and stop". target must be an existing element with that animation ("element x does not exist", "element x has no animation y"). Same permission and timing rules as stage.sprite. Limit: 64 triggers per script; the same id replaces. The shot fires in the very frame the note is judged.

Types

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

type StageEmitter = {
  id: string;
  layer?: StageLayer | null;
  at: StagePoint;
  image?: string | null;
  size: number;
  color?: string | null;
  endColor?: string | null;
  lifetimeMs: number;
  speed?: number | null;
  speedJitter?: number | null;
  direction?: number | null;
  spread?: number | null;
  gravity?: number | null;
  burst?: number | null;
  rate?: number | null;
  maxParticles: number;
  fade?: boolean | null;
  shrink?: boolean | null;
};

type StageLayer = "below" | "lanes" | "above";

type StagePoint = {
  space?: StageSpace | null;
  column?: number | null;
  x?: number | null;
  y?: number | null;
};

type StageSpace = "screen" | "playfield" | "lane" | "receptor";

type StageCue = { target: string; animation: string; };

type StageRect = {
  id: string;
  layer?: StageLayer | null;
  at: StagePoint;
  size: StageSize;
  color?: string | null;
  radius?: number | null;
  opacity?: number | null;
  rotation?: number | null;
  scale?: number | null;
  animations?: Record<string, StageAnimation> | null;
};

type StageSize = { width: number; height: number; };

type StageAnimation = {
  durationMs: number;
  easing?: Easing | null;
  repeat?: boolean | null;
  from?: StageProps;
  to?: StageProps;
};

type StageProps = {
  x?: number | null;
  y?: number | null;
  scale?: number | null;
  rotation?: number | null;
  opacity?: number | null;
  color?: string | null;
};

type StageSprite = {
  id: string;
  layer?: StageLayer | null;
  at: StagePoint;
  image: string;
  size: StageSize;
  color?: string | null;
  opacity?: number | null;
  rotation?: number | null;
  scale?: number | null;
  animations?: Record<string, StageAnimation> | null;
};

type StageText = {
  id: string;
  layer?: StageLayer | null;
  at: StagePoint;
  text: string;
  size: number;
  color?: string | null;
  align?: StageAlign | null;
  opacity?: number | null;
  rotation?: number | null;
  scale?: number | null;
  animations?: Record<string, StageAnimation> | null;
};

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

type StageTrigger = {
  id: string;
  on: StageEvent;
  target: string;
  play?: string | null;
  stop?: string | null;
};

type StageEvent = {
  judgement?: StageJudgementFilter | null;
  press?: StageColumn | null;
  release?: StageColumn | null;
  holdStart?: StageColumn | null;
  holdEnd?: StageColumn | null;
};

type StageJudgementFilter = {
  tier?: number | null;
  column?: number | null;
  miss?: boolean | null;
};

type StageColumn = { column?: number | null; };

Defined elsewhere

Easing (game)

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