Hello, I'm attempthing to put audio into my SFML 2.0 game and have hit a bit of a road-block.
I can play audio fine my my games main function with this code:
sf::SoundBuffer buffer;
if (!buffer.loadFromFile("sound file name"))
{
std::cout<<"failed to load sound"<<std::endl;
}
sf::Sound sound(buffer);
sound.play();
but I want another class, PlaySoundEvent to be able to trigger sounds, but this just dosent work.
PlaySoundEvent is a fairly simple class, you pass it a buffer and then call the fire(), witch just creates a sf::Sound with the supplied buffer and then plays it.
so the code:
sf::SoundBuffer buffer;
if (!buffer.loadFromFile("sound file name"))
{
std::cout<<"failed to load sound"<<std::endl;
}
PlaySoundEvent sndEvent(buffer);
sndEvent.fire();
should work exactly the same as above, but it dosen't.
Have I massed up my includes?
PlaySoundEvent .fire() looks like this:
void PlaySoundEvent::fire()
{
sf::Sound soundObj(sound);
soundObj.setVolume(100);
soundObj.play();
}