Sound effects

We have many gameplay events that can be represented by sounds: Fired machine guns, launched missiles, explosions, collection of pickups, and so on. Unlike music, sound effects are mostly very short. As a consequence, they can be loaded completely into memory, and we can also use the raw WAV format for these files without wasting too much memory. We are going to use the sf::SoundBuffer resource class to store the audio samples for our sound effects.

The following enumeration of sound effects is used in our game. We'll also create a typedef for the resource holder of sf::SoundBuffer.

namespace SoundEffect { enum ID { AlliedGunfire, EnemyGunfire, Explosion1, Explosion2, LaunchMissile, CollectPickup, Button, }; } typedef ResourceHolder<sf::SoundBuffer, ...

Get SFML Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.