October 2016
Beginner
520 pages
10h 19m
English
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: ...
Read now
Unlock full access