Musicclass
Background music. Plays one track at a time and crossfades between them, through the "Music" mixer. This lives outside any scene, so music keeps playing (or fading) through loading screens and scene changes until something plays another track or stops it. `Sandbox.Sound.StopAll(System.Single)` stops it too. For layered stems or streaming from a url use `Sandbox.MusicPlayer` instead.
Methods4
Showing 4 methods
public static System.IDisposable Duck(float amount = 0.8, float fade = 0.3)
Turn the music down while something more important plays over it - a trailer, a cutscene, a bit of dialogue. `amount` is how much to duck by: 0.9 leaves the music at 10% of its volume, 1 silences it completely. The track carries on playing underneath either way. The music stays ducked until the returned handle is disposed, then fades back up - so hold onto it for as long as you're playing over the top. If several things duck at once the strongest one wins, so they don't need to know about each other.
| Parameter | Type | Description |
|---|---|---|
| amount = 0.8 | float | How much to turn the music down, 0 to 1. |
| fade = 0.3 | float | Seconds to fade down, and back up again afterwards. |
IDisposable—public static void Stop(float fade = 1)
Fade out and stop the current track.
| Parameter | Type | Description |
|---|---|---|
| fade = 1 | float | — |
void—No results match this filter.
Properties6
Showing 6 properties
public static float Sandbox.Game.Music.Amplitude { get; set; }
How loud the music is right now, for visualisers. 0 when nothing is playing.
float—public static float Sandbox.Game.Music.Ducking { get; set; }
How much the music is turned down right now, 0 (not at all) to 1 (silent). This eases towards the strongest active duck, so it lags behind while fading.
float—public static bool Sandbox.Game.Music.IsPlaying { get; set; }
True if a track is playing or fading in.
bool—public static bool Sandbox.Game.Music.Paused { get; set; }
Pause or resume the current track.
bool—public static Sandbox.SoundFile Sandbox.Game.Music.Track { get; set; }
The track currently playing, or null.
public static float Sandbox.Game.Music.Volume { get; set; }
Music volume, 0 to 1, on top of the track's own volume. This is a straight volume control for the game to use - a user setting belongs on the Music mixer, and turning the music down for a moment is what `Sandbox.Game.Music.Duck(System.Single,System.Single)` is for.
float—No results match this filter.