-
Notifications
You must be signed in to change notification settings - Fork 4
Guide: Playing sound effects & music
BNA internally uses the SoLoud sound library. Sound effects can be conveniently loaded from disk as WAVs, FLACs, OGGs, or MP3s & played back either in 2D or 3D, and can also be played as background songs.
You can load a sound effect from disk, either in-memory or streaming:
using BNA.Audio;
// ...
SoundEffect mySoundEffect;
if(SoundEffect.Load("./Content/Audio/mySound.ogg") case .Ok(let sfx)) // or LoadStreaming if you want to stream from disk instead of reading & decompressing the whole file in at once
{
mySoundEffect = sfx;
}
And then play it, getting a handle to the new playing instance:
let sfxHandle = Audio.Play( mySoundEffect ); // or Play3D
You can also construct a Song, which wraps two different SoundEffects: the first sound effect is optional and is a non-looping intro portion to play. The second sound effect is required, and is a looping portion to be "stitched" onto the intro portion and repeats forever afterwards.
let song = Song(myIntroSoundEffect, myLoopSoundEffect);
let songHandle = Audio.PlaySong( song );
Getting Started
Drawing Sprites
Loading & Applying Effects
Loading Textures
Creating vertex & index buffers and drawing geometry
Using render buffers
Playing sound effects & music
Routing sound through buses & applying filters
Game
GameWindow
GraphicsDevice
SpriteBatch
Audio
Keyboard
Mouse
GamepadDevice