O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing sounds

Due to the limitations on the number of sounds we can have in an application, it's best to have a centralized way of handling and recycling them. This is where the SoundManager class comes in. Let's begin aliasing a data type for sound IDs:

using SoundID = int;

A simple integer type is more than qualified for the job of keeping sounds identified.

Additionally, we'll want to store some information with the sound instance:

struct SoundInfo{
    SoundInfo(const std::string& l_name): m_name(l_name), m_manualPaused(false){}
    std::string m_name;
    bool m_manualPaused;
};

In order to properly deallocate resources when it counts, we're going to want to store the string identifier of the audio file that the sound is using. Keeping track of whether ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required