From f78cd2c3f18328053866c43fbe4d59c817091fdc Mon Sep 17 00:00:00 2001 From: ineslelin Date: Mon, 24 Jun 2024 22:53:13 +0200 Subject: [PATCH] added some tweaks to playSound --- src/GameInternal.cpp | 4 ++-- src/SoundManager.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/GameInternal.cpp b/src/GameInternal.cpp index 5e23c78..74d2a77 100644 --- a/src/GameInternal.cpp +++ b/src/GameInternal.cpp @@ -152,8 +152,8 @@ void GameInternal::init(const char* title, int xpos, int ypos, int width, int he assets->addTexture("egg", "assets/egg.png"); */ // loading sounds - assets->addSoundEffect("throw_egg", "assets/sound/throw_egg.wav"); - assets->addSoundEffect("steps", "assets/sound/steps.wav"); + // assets->addSoundEffect("throw_egg", "assets/sound/throw_egg.wav"); + // assets->addSoundEffect("steps", "assets/sound/steps.wav"); // loading music // assets->addMusic("background_music", "assets/sound/background_music.mp3"); diff --git a/src/SoundManager.cpp b/src/SoundManager.cpp index 65d3bf5..2954b9f 100644 --- a/src/SoundManager.cpp +++ b/src/SoundManager.cpp @@ -51,8 +51,16 @@ void SoundManager::playSound(GameInternal* game, std::string sound, bool canOver { if(!canOverlap) { - if (Mix_Playing(channel) != 0) - Mix_HaltChannel(channel); + // dev needs to specify a channel for this check to work, if they set it to -1 and let sdl pick the first available + // channel mix_getchunk() won't work + if (Mix_Playing(channel) != 0 && + Mix_GetChunk(channel) == game->assets->getSound(sound) && + channel != -1) + { + return; + } + + Mix_HaltChannel(channel); } if(Mix_VolumeChunk(game->assets->getSound(sound), volume) == -1)