Hi there. Y'all have been very helpful in the past, so I turn to you again! I hope this question hasn't been asked many times. I did a search and didn't see anything on it so...
When the player in my game dies, I want all sf::Sounds and sf::Musics playing to stop for a (hopefully) dramatic effect. Kind of like when you die in MegaMan.
When I call to my SoundManager class (which is very basic, mostly std::maps to hold sf::Sound and sf::Musics) to stop all playing sounds and musics, it works, but then my game lags like crazy.
Here is the relevant code, as far as I can tell:
void SoundManager::stopAll()
{
stopAllSounds();
stopAllMusic();
}
void SoundManager::stopAllSounds()
{
if(_soundVolume == 0)
return;
std::map<string, Sound::Ptr>::iterator itr;
for (itr = _sounds.begin(); itr != _sounds.end(); itr++)
{
itr->second->stop();
}
}
void SoundManager::stopAllMusic()
{
if(_musicVolume == 0)
return;
std::map<string, sf::Music*>::iterator itr;
for (itr = _musics.begin(); itr != _musics.end(); itr++)
{
itr->second->stop();
}
}
Now, I'm wondering whether iterating over the map is just eating my memory, or if I'm not supposed to be storing and using Sounds this way and should instead be using a soundBuffer... but who knows. I don't really understand what the point of a SoundBuffer is, even though I've read the documentation. I am not well versed in sound file technology and terminology.
Any help would be much appreciated!