0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

added some tweaks to playSound

This commit is contained in:
ineslelin 2024-06-24 22:53:13 +02:00
parent 24e69b73a2
commit f78cd2c3f1
2 changed files with 12 additions and 4 deletions

View File

@ -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");

View File

@ -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)