From e0fab912606bb9fe505b951d41ecbc6cef168023 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 17 Mar 2025 20:47:41 -0400 Subject: [PATCH] Fix an error with sound positioning in play_sound. --- sound.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sound.py b/sound.py index b68cdf4..70a956f 100644 --- a/sound.py +++ b/sound.py @@ -84,27 +84,28 @@ class Sound: def play_sound(self, soundName, volume=1.0, loop=False): """Play a sound with current volume settings applied. - + Args: soundName (str): Name of sound to play volume (float): Base volume for the sound (0.0-1.0, default: 1.0) loop (bool): Whether to loop the sound (default: False) - + Returns: pygame.mixer.Channel: The channel the sound is playing on """ if soundName not in self.sounds: return None - + sound = self.sounds[soundName] # Set loop parameter to -1 for infinite loop or 0 for no loop loopParam = -1 if loop else 0 - + channel = sound.play(loopParam) if channel: - channel.set_volume(volume * self.volumeService.get_sfx_volume()) - + sfx_volume = volume * self.volumeService.get_sfx_volume() + channel.set_volume(sfx_volume, sfx_volume) # Explicitly set both channels to ensure centered sound + # Store in active loops if looping if loop: self.activeLoops[soundName] = { @@ -112,7 +113,7 @@ class Sound: 'sound': sound, 'volume': volume } - + return channel def stop_sound(self, soundName=None, channel=None): @@ -836,7 +837,8 @@ def play_sound(sound, volume=1.0, loop=False): channel = sound.play(loopParam) if channel: - channel.set_volume(volume * volumeService.get_sfx_volume()) + sfx_volume = volume * volumeService.get_sfx_volume() + channel.set_volume(sfx_volume, sfx_volume) # Explicitly set both channels to ensure centered sound return channel def obj_play(sounds, soundName, playerPos, objPos, playerY=0, objY=0, loop=False):