C# Класс 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).
Показать файл Открыть проект

Открытые методы

Метод Описание
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

Приватные методы

Метод Описание
OnFadeOver ( object source, System.Timers.ElapsedEventArgs e ) : void
OnFadeOverFadeIn ( object source, System.Timers.ElapsedEventArgs e ) : void
tryAllFileTypes ( string fileName ) : bool

Описание методов

dispose() публичный статический Метод

Disposes of all resources contained in BGMusic. Call this method at the end of the Game's life.
public static dispose ( ) : void
Результат void

fadeIn() публичный статический Метод

Song starts from silence and fades in to full volume. Default fade in time.
public static fadeIn ( ) : void
Результат void

fadeIn() публичный статический Метод

Song starts from silence and fades in to full volume
public static fadeIn ( double fadeTime ) : void
fadeTime double Time to fade in, in milliseconds
Результат void

fadeOut() публичный статический Метод

Song starts from full volume and fades out to silence. Default fade out time.
public static fadeOut ( ) : void
Результат void

fadeOut() публичный статический Метод

Song starts from full volume and fades out to silence
public static fadeOut ( double fadeTime ) : void
fadeTime double Time to fade out, in milliseconds
Результат void

isLooping() публичный статический Метод

Specifies whether a song is looping (true by default)
public static isLooping ( ) : bool
Результат bool

isPaused() публичный статический Метод

Specifies whether the soundtrack is paused (false if is playing)
public static isPaused ( ) : bool
Результат bool

playSong() публичный статический Метод

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
Результат void

setLooping() публичный статический Метод

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
Результат void

setPaused() публичный статический Метод

Sets whether the soundtrack is paused or not
public static setPaused ( bool pause ) : void
pause bool
Результат void

setVolume() публичный статический Метод

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
Результат void

stopSong() публичный статический Метод

Stops song and disposes of it (cannot be resumed afterward)
public static stopSong ( ) : void
Результат void

transitionToSong() публичный статический Метод

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
Результат void

transitionToSong() публичный статический Метод

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
Результат void

transitionToSongWithFadeIn() публичный статический Метод

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
Результат void

transitionToSongWithFadeIn() публичный статический Метод

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
Результат void