Mercurial > rinkhals
changeset 97:529a4d41c67a
Rather use sound playing (we don't need to stream sound effects from disk), and cache sounds
author | David Fraser <davidf@sjsoft.com> |
---|---|
date | Wed, 02 Sep 2009 11:52:02 +0000 |
parents | a851461d345e |
children | 725b292ca07b |
files | gamelib/sound.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/sound.py Wed Sep 02 11:40:51 2009 +0000 +++ b/gamelib/sound.py Wed Sep 02 11:52:02 2009 +0000 @@ -15,14 +15,18 @@ except pygame.error, exc: print >>sys.stderr, "Could not initialize sound system: %s" % exc +SOUND_CACHE = {} + def play_sound(filename): """plays the sound with the given filename from the data sounds directory""" if not SOUND_INITIALIZED: return file_path = data.filepath("sounds", filename) - if not os.path.exists(file_path): - return - pygame.mixer.music.load(file_path) - pygame.mixer.music.play() + sound = SOUND_CACHE.get(file_path, None) + if not sound: + if not os.path.exists(file_path): + return + SOUND_CACHE[file_path] = sound = pygame.mixer.Sound(file_path) + sound.play()