Hello, for some reason my sounds stop after a while, music continues playing as normal though.
I suspect it could have something to do with the frequency of the sound instance creation(Quite often), could it have something to do with that?
Init, called once on init.
if (!Music.OpenFromFile("DJYeoh0.ogg"))
{
MessageBox(hWnd,"Failed to load DJYeoh0.ogg.","Warning",MB_ICONEXCLAMATION | MB_OK);
return false;
}
if (!Buffer.LoadFromFile("laser0.ogg"))
{
MessageBox(hWnd,"Failure to load from file.","Warning",MB_ICONEXCLAMATION | MB_OK);
return false;
}
Create, this gets called each time a unit shoots/dies.
sf::Sound *temp_sound = new sf::Sound;
temp_sound->SetBuffer(ps->app->Buffer);
ps->sound_vec.push_back(temp_sound);
temp_sound->SetPitch(3);
temp_sound->Play();
Update called each frame
std::vector<sf::Sound*>::iterator sound_it = sound_vec.begin();
while(sound_it != sound_vec.end()){
int duration = (*sound_it)->GetBuffer()->GetDuration();
int elapsed = (*sound_it)->GetPlayingOffset();
if(elapsed >= duration){
sound_it = sound_vec.erase(sound_it);
}
else
sound_it++;
}
Thanks.