Game Development Reference
In-Depth Information
The sf::Sound class
A sound is composed of two classes, Sound and SoundBuffer . The SoundBuffer
class is the resource in the memory and Sound is the wrapper that plays the resource.
This should ring a bell, since it uses the same structure as Sprite and Tex-
ture Sprite uses Texture as a resource. By designing it in such a way, multiple
Sound instances can use the same SoundBuffer instance, reducing the amount of
memory required significantly.
Enough with the explanations, here is how we create a sound:
We use the same format to load Texture as we do here with SoundBuffer —check
whether the loading has failed and do something accordingly. In this case, without a sound
buffer, it doesn't make sense to continue with the program execution, so we will terminate
it. Some of the common supported audio formats are: OGG, WAV, FLAC, and so on. It is
important to note that MP3 is not supported due to licensing issues.
Search WWH ::




Custom Search