Okay, so in order to play multiple instances of the same sound over top of each other (such as laser shots or explosions), I have created a vector to contain the Sound objects.
A SoundBuffer object matching each of my wav files is stored as a member in my file manager object and is always alive.
First I call my PlaySound function:
PlaySound(loads.MyBuffer);
This is my complete PlaySound function:
void Game::PlaySound(sf::SoundBuffer& buffer){
soundbox.push_back(sf::Sound(buffer));
soundbox[soundbox.size()-1].Play();
}
Then, I have a function that sits in my main loop that checks if each sound has finished playing, and if it has, it gets destroyed. Here is that function:
void Game::DestroySounds(){
for(std::vector<sf::Sound>::iterator iter = soundbox.begin(); iter != soundbox.end(); ){
if(!iter->GetStatus()){
iter = soundbox.erase(iter);
}else{
++iter;
}
}
}
All this works. However, as soon as one of the Sound objects is erased from the vector, the most recent Sounds that share the same SoundBuffer as the erased Sound are stopped short if they were still playing.
Any advice?