O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding support for sound

In order to make our entities emit sounds, some preparations have to be made. For now, we're only going to concern ourselves with simply adding the sound of footsteps whenever a character walks. Doing so requires a slight modification of the EntityMessage enumeration in EntityMessages.h:

enum class EntityMessage{ 
  Move, Is_Moving, Frame_Change, State_Changed, Direction_Changed,
  Switch_State, Attack_Action, Dead
};

The highlighted bits are what we're going to be focusing on. Frame_Change is a new type of message that's been added in this chapter, and Direction_Changed will be used to manipulate the sound listener's direction. In order to detect when a frame changes during the animation process, however, we're going to need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required