C# Class SunsetHigh.BGMusic

Static class for managing all the background music for the game, using the NAudio library. Currently supports playing, pausing, resuming, stopping, fading in and out, and looping. Fading effects are recommended when changing screens/songs. When providing song file names, please specify the file extension (it's not necessary, but recommended).
Afficher le fichier Open project: ErraticUnicorn/MOSH

Méthodes publiques

Méthode Description
dispose ( ) : void

Disposes of all resources contained in BGMusic. Call this method at the end of the Game's life.

fadeIn ( ) : void

Song starts from silence and fades in to full volume. Default fade in time.

fadeIn ( double fadeTime ) : void

Song starts from silence and fades in to full volume

fadeOut ( ) : void

Song starts from full volume and fades out to silence. Default fade out time.

fadeOut ( double fadeTime ) : void

Song starts from full volume and fades out to silence

isLooping ( ) : bool

Specifies whether a song is looping (true by default)

isPaused ( ) : bool

Specifies whether the soundtrack is paused (false if is playing)

playSong ( string fileName ) : void

Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.

setLooping ( bool looping ) : void

Sets whether a song should loop upon ending (true by default)

setPaused ( bool pause ) : void

Sets whether the soundtrack is paused or not

setVolume ( float volume ) : void

Changes the volume of playback; BGMusic.SILENCE can be used for muting the song, while BGMusic.FULL_VOLUME can unmute.

stopSong ( ) : void

Stops song and disposes of it (cannot be resumed afterward)

transitionToSong ( string fileName ) : void

Fades out the current song and starts playing the new song after a short lag. Default fade time and lag times are used.

transitionToSong ( string fileName, double fadeTime, double lagTime ) : void

Fades out the current song and starts playing the new song after a short lag

transitionToSongWithFadeIn ( string fileName ) : void

Fades out the current song and starts fading into the new song after a short lag. Default fade and lag times are used.

transitionToSongWithFadeIn ( string fileName, double fadeTime, double lagTime ) : void

Fades out the current song and starts fading into the new song after a short lag

Private Methods

Méthode Description
OnFadeOver ( object source, System.Timers.ElapsedEventArgs e ) : void
OnFadeOverFadeIn ( object source, System.Timers.ElapsedEventArgs e ) : void
tryAllFileTypes ( string fileName ) : bool

Method Details

dispose() public static méthode

Disposes of all resources contained in BGMusic. Call this method at the end of the Game's life.
public static dispose ( ) : void
Résultat void

fadeIn() public static méthode

Song starts from silence and fades in to full volume. Default fade in time.
public static fadeIn ( ) : void
Résultat void

fadeIn() public static méthode

Song starts from silence and fades in to full volume
public static fadeIn ( double fadeTime ) : void
fadeTime double Time to fade in, in milliseconds
Résultat void

fadeOut() public static méthode

Song starts from full volume and fades out to silence. Default fade out time.
public static fadeOut ( ) : void
Résultat void

fadeOut() public static méthode

Song starts from full volume and fades out to silence
public static fadeOut ( double fadeTime ) : void
fadeTime double Time to fade out, in milliseconds
Résultat void

isLooping() public static méthode

Specifies whether a song is looping (true by default)
public static isLooping ( ) : bool
Résultat bool

isPaused() public static méthode

Specifies whether the soundtrack is paused (false if is playing)
public static isPaused ( ) : bool
Résultat bool

playSong() public static méthode

Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.
public static playSong ( string fileName ) : void
fileName string File name of the song in the "Content" directory
Résultat void

setLooping() public static méthode

Sets whether a song should loop upon ending (true by default)
public static setLooping ( bool looping ) : void
looping bool True if the song should loop, false otherwise
Résultat void

setPaused() public static méthode

Sets whether the soundtrack is paused or not
public static setPaused ( bool pause ) : void
pause bool
Résultat void

setVolume() public static méthode

Changes the volume of playback; BGMusic.SILENCE can be used for muting the song, while BGMusic.FULL_VOLUME can unmute.
public static setVolume ( float volume ) : void
volume float
Résultat void

stopSong() public static méthode

Stops song and disposes of it (cannot be resumed afterward)
public static stopSong ( ) : void
Résultat void

transitionToSong() public static méthode

Fades out the current song and starts playing the new song after a short lag. Default fade time and lag times are used.
public static transitionToSong ( string fileName ) : void
fileName string File name of the new song to play in the "Content" folder
Résultat void

transitionToSong() public static méthode

Fades out the current song and starts playing the new song after a short lag
public static transitionToSong ( string fileName, double fadeTime, double lagTime ) : void
fileName string File name of the new song to play in the "Content" folder
fadeTime double Time to fade out, in milliseconds
lagTime double Lag time between the two songs (excluding fade time), in milliseconds
Résultat void

transitionToSongWithFadeIn() public static méthode

Fades out the current song and starts fading into the new song after a short lag. Default fade and lag times are used.
public static transitionToSongWithFadeIn ( string fileName ) : void
fileName string File name of the new song to play in the "Content" folder
Résultat void

transitionToSongWithFadeIn() public static méthode

Fades out the current song and starts fading into the new song after a short lag
public static transitionToSongWithFadeIn ( string fileName, double fadeTime, double lagTime ) : void
fileName string File name of the new song to play in the "Content" folder
fadeTime double Time to fade out and fade in (each), in milliseconds
lagTime double Lag time between the two songs (excluding fade time), in milliseconds
Résultat void