Music themes
First, we want to play background music depending on the state we are currently in. We have prepared two themes: One for the menu, and one for the game itself. We'll define a corresponding enum
:
namespace Music { enum ID { MenuTheme, MissionTheme, }; }
We'll then create a class that has an interface dedicated to music playing:
class MusicPlayer : private sf::NonCopyable { public: MusicPlayer(); void play(Music::ID theme); void stop(); void setPaused(bool paused); void setVolume(float volume); private: sf::Music mMusic; std::map<Music::ID, std::string> mFilenames; float mVolume; };
The method names should be self-explanatory. We have a single sf::Music
instance that represents the currently-played music. The
mFilenames
variable maps music...