Audio Methods
SplashKit also provides methods you can use to load and play sound effects and music. You can use sound effects to play multiple different sounds that are mixed together when played, while music is designed for longer running background sound for your applications with only one music track being able to be played at once.
Playing sound effects
Sound effects are designed to be used for short sounds that are triggered by actions in your program. You can play several sound effects at the same time.
SplashKit can handle several file formats for sound effects, but the best and most reliable is Ogg Vorbis. You can use programs like Audacity to edit and convert sound effects to the Ogg Vorbis format.
Method | Required Arguments | Description |
---|---|---|
Load Sound Effect | the name of the sound effect and its filename | As with LoadBitmap , but this loads the sound effect into your program. You can use the name to access this sound effect in other method calls. The filename can be the full path to a file, or the filename of a file in the Resources/sounds folder. |
Play Sound Effect | the name of a loaded sound effect | Plays the sound effect once at its full volume. |
the name of a loaded sound effect, volume (float ) | Plays the sound effect once at a percentage of its full volume. The volume should be between 0 and 1.0 | |
the name of a loaded sound effect, times (int ) | Plays the sound effect multiple times in a row at full volume. | |
the name of a loaded sound effect, times (int ), volume (float ) | Plays the sound effect multiple times in a row at a percentage of its full volume. | |
Stop Sound Effect | the name of a loaded sound effect | Stops playing the indicated sound effect. |
These methods have the following declaration:
Find a sound effect you like and try out this program:
Playing music
Music is designed to work with long playing background audio. Unlike sound effects, you can only play one music track at a time. This means you can have one music track playing and several sound effects.
As with sound effects, The Ogg Vorbis format works best with SplashKit for music.
Method | Required Arguments | Description |
---|---|---|
Load Music | the name of the music and its filename | As with LoadBitmap , but this loads the music into your program. You can use the name to access this music in other method calls. The filename can be the full path to a file, or the filename of a file in the Resources/sounds folder. |
Play Music | the name of the loaded music | Plays the indicated music track once. This will switch tracks if other music was already playing. |
the name of the loaded music, a number of times to play | Plays the indicated music track the number of times indicated (-1 means infinitely). | |
Fade Music In | the name of the loaded music, and a number of milliseconds (int) | Plays the indicated music track, starting softly and increasing to full volume over the indicated time. |
Fade Music Out | a number of milliseconds (int) | Stops playing music, fading out over the indicated time. |
Set Music Volume | a value between 0 and 1.0 (float) | Set the volume to a proportion of full volume. |
Stop Music | none | Stops the music playing. |
These have the following declarations in C#:
Try out playing some music using SplashKit with the following code: