From c6b5e936ff9869d8a3de9ea41db784a4cb46a818 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Mar 2021 11:43:29 -0500 Subject: Sound effects are paused on the pause menu #7 --- src/menu_system.cpp | 2 ++ src/mixer.cpp | 8 ++++++++ src/mixer.h | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/menu_system.cpp b/src/menu_system.cpp index 6b03fca..7631e4d 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp @@ -10,6 +10,7 @@ void MenuSystem::tick(double dt) { openState_ = OpenState::Closed; game_.unpauseGameplay(); + game_.getMixer().unpauseSounds(); } else if (pauseAnimation_.getProgress() == 1.0) { openState_ = OpenState::Open; } @@ -64,6 +65,7 @@ void MenuSystem::openPauseMenu() { cursor_ = 0; + game_.getMixer().pauseSounds(); game_.getMixer().playSound("../res/sfx/menu_open.wav"); } diff --git a/src/mixer.cpp b/src/mixer.cpp index 37c2177..4e8f307 100644 --- a/src/mixer.cpp +++ b/src/mixer.cpp @@ -23,6 +23,14 @@ void Mixer::stopChannel(int channel) { Mix_HaltChannel(channel); } +void Mixer::pauseSounds() { + Mix_Pause(-1); +} + +void Mixer::unpauseSounds() { + Mix_Resume(-1); +} + void Mixer::playMusic(std::string_view name, int ms) { Mix_Music* song = getMusicByName(name); int ret; diff --git a/src/mixer.h b/src/mixer.h index b049118..854c67d 100644 --- a/src/mixer.h +++ b/src/mixer.h @@ -72,6 +72,10 @@ public: void stopChannel(int channel); + void pauseSounds(); + + void unpauseSounds(); + // name is the name of the file, not containing the extension // ms is the time in milliseconds to fade in void playMusic(std::string_view name, int ms = 0); -- cgit 1.4.1