Concept
Snapshot
Capture a mix state. Apply it later with a smooth crossfade. Your menu/gameplay/boss switcher in one call.
TL;DR
A Snapshot is an immutable record of bus levels, mutes, and
parameter values. Capture once when the mix is right, then re-apply
later with fadeMs to crossfade the whole mix in one call.
No more orchestrating ten fadeTo calls by hand.
Mental model
API surface
engine.captureSnapshot(name): Snapshot
engine.snapshot(name, state): Snapshot
class Snapshot {
readonly name: string;
readonly state: SnapshotState;
apply(options?: { fadeMs?: number }): Promise<void>;
} Live demo
Three presets, 800 ms crossfade between mixes.
Recipes
Capture from the live engine
// Set the mix to a known-good "menu" state, then capture it.
engine.bus('music').level = 0.8;
engine.bus('sfx').level = 0.3;
const menu = engine.captureSnapshot('menu'); Build from explicit state
// Build a snapshot from explicit state — no need to mutate the live engine.
const boss = engine.snapshot('boss', {
buses: {
music: { level: 1.0, muted: false },
sfx: { level: 0.8, muted: false },
},
parameters: { intensity: 1.0 },
}); Switch with crossfade
await menu.apply({ fadeMs: 250 }); // crossfade everything in 250ms
await boss.apply({ fadeMs: 800 }); Pitfalls
Snapshots don't include voices.
They restore the mix, not what's playing on it. If you need a
"boss music starts" effect, trigger the boss music yourself then
apply the snapshot.
Capturing twice does not snapshot motion.
A snapshot is a single moment. To animate a fade-in over time, drive a
Parameter instead.