if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (gameState->mPlayerFireCooldown <= 0.0f)
{
// ...
sf::SoundBuffer w;
w.loadFromFile("../assets/shot.wav");
sf::Sound s;
s.setBuffer(w);
s.play();
}
}
Seems normal. Isn't it? I've spent thetwo hours on google and couldn't find a solution.
Any ideas?
Thanks in advance.
Yes, it plays in a thread, which is why play() is non-blocking. (= the program continues to run while the sound plays) But that thread dies when the Sound is destroyed.
// outside your main loop
sf::SoundBuffer w;
sf::Sound s;
//...
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (gameState->mPlayerFireCooldown <= 0.0f)
{
// ...
w.loadFromFile("../assets/shot.wav");
s.setBuffer(w);
s.play();
}
}
You could even load your sound before the main loop, since loading can take time.