How SFML handles spatialization
SFML has a number of 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 ready to be played, as we have done so often, as follows:
// 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, as 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 values are arbitrary...