GameSequencer
Methods
- .effectCallback({ scene })
- .start()
- .stop()
- .define(tag, registry)
- .subscribe(context, callback)
A musical sequencer that plays during gameplay. Automatically starts when the game enters the playing state and stops when it leaves. Supports two modes via the mode attribute:
sequence(default) — Loops a note pattern at a BPM that ramps fromstart-bpmtoend-bpmover the timer duration, creating a sense of mounting urgency.hum— Plays a rising sine oscillator that glides fromroottoend-freq, with an initial silent period controlled bysilent-fraction.
Attributes
- notes
-
string— A comma-separated list of semitone offsets from the root frequency. Usenullor empty entries for rests. The pattern loops continuously.notes="0,4,7,12,7,4"This defines a major arpeggio pattern: root, major third, fifth, octave, fifth, major third.
- root
-
number— Root frequency in hertz. Defaults to261.63(middle C). All semitone offsets innotesare calculated relative to this frequency. - start-bpm
-
number— Starting tempo in beats per minute. Defaults to72. - end-bpm
-
number— Target tempo in beats per minute. Defaults to160. The sequencer ramps fromstart-bpmtoend-bpmover the timer duration using an ease-in curve — the tempo increases slowly at first, then accelerates rapidly in the final third. - gain
-
number— Volume level from0to1. Defaults to0.07. Keep this low so the sequencer sits in the background. - type
-
string— Synth type for the notes. Defaults to"marimba". Uses the same additive sine partial engine asGameSample. - mode
-
"sequence" | "hum"— Playback mode. Defaults to"sequence". In"hum"mode thenotes,start-bpm,end-bpm, andtypeattributes are ignored; a continuous oscillator rises fromroottoend-freqinstead. - end-freq
-
number— Target frequency in hertz forhummode. The oscillator glides fromrootto this value over the timer duration. Defaults to220. Has no effect insequencemode. - silent-fraction
-
number— Fraction of the total timer duration that stays silent at the start ofhummode (0–1). Defaults to0.25(first 25% is silent). Has no effect insequencemode.
Methods
- .start()
-
Start the sequencer manually. Reads the
<game-timer>duration from the nearest shell to calculate the BPM ramp duration. Normally called automatically when the game enters theplayingstate. - .stop()
-
Stop the sequencer. Called automatically when the game leaves the
playingstate.
Timer Integration
The sequencer reads the duration attribute from the first <game-timer> inside the same <game-shell> to determine how long the BPM ramp lasts. If no timer is found, it defaults to 10 seconds.
BPM Ramp Curve
The tempo does not increase linearly. An ease-in curve is applied:
- First 60% of the timer — gentle acceleration (tempo reaches roughly 40% of the way from start to end BPM).
- Final 40% of the timer — rapid acceleration to the target BPM.
This means the player feels comfortable at first, with tension building sharply as time runs out.
Signal Access
| Signal | Usage |
|---|---|
| Shell signals | Reads scene signal from the shell to auto-start during playing and auto-stop otherwise |
Usage
<game-sequencer
notes="0,4,7,12,7,4"
root="261.63"
start-bpm="72"
end-bpm="160"
gain="0.07"
></game-sequencer>
A minor-key tension pattern:
<game-sequencer
notes="0,3,7,null,12,7,3,null"
root="220"
start-bpm="80"
end-bpm="180"
gain="0.06"
></game-sequencer>