Adding background music
Any game would be incomplete if it did not have any background music. So it is very important that we integrate a way to play music into our C++ engine. There are various ways to do this. We are going to use SDL to play music in our game.
Getting ready
You need a Windows machine and a working copy of Visual Studio. The SDL library is also required.
How to do it…
In this recipe, we will find out how easy it is to play background music:
- Add a source file called
Source.cpp
. - Add the following code to it:
#include <iostream> #include "../AudioDataHandler.h" #include "../lib/SDL2/include/SDL2/SDL.h" #include "iaudiodevice.hpp" #include "iaudiocontext.hpp" #include "audioobject.hpp" #include "sdl/sdlaudiodevice.hpp" #include "sdl/sdlaudiocontext.hpp" #define FILE_PATH "./res/audio/testClip.wav" int main(int argc, char** argv) { SDL_Init(SDL_INIT_AUDIO); IAudioDevice* device ...