Audio manager

Similar to what we did for textures and fonts, we're going to need a way to manage sf::SoundBuffer instances easily. Luckily, our ResourceManager class is there to make it extremely convenient, so let's create the AudioManager.h file and define the way sound buffers are set up:

class AudioManager : public ResourceManager<
  AudioManager, sf::SoundBuffer>
{
public:
  AudioManager() : ResourceManager("audio.cfg"){}

  sf::SoundBuffer* Load(const std::string& l_path){
    sf::SoundBuffer* sound = new sf::SoundBuffer();
    if (!sound->loadFromFile(
      Utils::GetWorkingDirectory() + l_path))
    {
      delete sound;
      sound = nullptr;
      std::cerr << "! Failed to load sound: "
        << l_path << std::endl;
    }
    return sound;
  }
};

As you can tell already, the sound interface is ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.