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, SoundEffect::ID> SoundBufferHolder;
We implement a class for the sound effects, one similar to the MusicPlayer
class:
class SoundPlayer : private sf::NonCopyable...