Game Development Reference
In-Depth Information
with a factor of 100, the sound has no transition period between its maximum volume and
0. A factor of 0 indicates that the sound is either heard by the listener at a maximum
volume (if it's in range) or it's just not played (outside the sound's minimum distance). At-
tenuation can be set by calling SoundSource::setAttenuation() . The default
value of the attenuation is 1.
Summarizing audio features
After all this talk about spatialization, it is a good idea to solidify everything by providing
an example that covers it all. We will create a simple yet effective world with one listener
and one audio source, which we can control with the mouse (position is controlled by
mouse coordinates, and the sound is played with a mouse button click.) Let's start with the
setup—one listener and one sound with appropriate visual indicators ( CircleShape ):
Since we are using AssetManager to load the sound buffers, it is important to create an
instance of it right after we create the window. Next, we place the listener at the center of
the window, and set it to face toward the top-border of the window (the y direction). We
also create a shape to display at the position of the renderer in the world . This will give us
a visual indication of where exactly the shape stands. After that, we create the sound and
set its minimal distance and attenuation properties. To finish off the initialization, we cre-
ate a shape for the sound as well.
Search WWH ::




Custom Search