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.

objectMusic
Namespace
global
Assembly
Sandbox.Engine
Declaration
public static abstract sealed class Sandbox.Game.Music

Methods4

Showing 4 methods

public static System.IDisposable Duck(float amount = 0.8, float fade = 0.3)PUBLICSTATIC

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.

ParameterTypeDescription
amount = 0.8floatHow much to turn the music down, 0 to 1.
fade = 0.3floatSeconds to fade down, and back up again afterwards.
Returns:IDisposable

public static void Stop(float fade = 1)PUBLICSTATIC

Fade out and stop the current track.

ParameterTypeDescription
fade = 1float
Returns:void

Properties6

Showing 6 properties

public static float Sandbox.Game.Music.Amplitude { get; set; }PUBLICSTATICGETSET

How loud the music is right now, for visualisers. 0 when nothing is playing.

Returns:float

public static float Sandbox.Game.Music.Ducking { get; set; }PUBLICSTATICGETSET

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.

Returns:float

public static bool Sandbox.Game.Music.IsPlaying { get; set; }PUBLICSTATICGETSET

True if a track is playing or fading in.

Returns:bool

public static bool Sandbox.Game.Music.Paused { get; set; }PUBLICSTATICGETSET

Pause or resume the current track.

Returns:bool

public static Sandbox.SoundFile Sandbox.Game.Music.Track { get; set; }PUBLICSTATICGETSET

The track currently playing, or null.

Returns:SoundFile

public static float Sandbox.Game.Music.Volume { get; set; }PUBLICSTATICGETSET

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.

Returns:float

On this page