Fix an error with sound positioning in play_sound.

This commit is contained in:
Storm Dragon 2025-03-17 20:47:41 -04:00
parent d513927d52
commit e0fab91260

View File

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