Handling spatialization using SFML
SFML has several functions that allow us to handle emitters, attenuation, and listeners. Let’s take a look at them hypothetically, and then we will write some code to add spatialized sound to our project for real.
We can set up a sound effect that is ready to be played, as we have already done so often, like this:
// Declare SoundBuffer in the usual way
SoundBuffer zombieBuffer;
// Declare a Sound object as-per-usual
Sound zombieSound;
// Load the sound from a file like we have done so often
zombieBuffer.loadFromFile("sound/zombie_growl.wav");
// Associate the Sound object with the Buffer
zombieSound.setBuffer(zombieBuffer);
We can set the position of the emitter using the setPosition
function shown in the following code:
// Set the horizontal and vertical positions of the emitter
// In this case the emitter is a zombie
// In the Zombie Arena project we could have used
// getPosition().x and getPosition().y
// These...