Changeset 97:529a4d41c67a


Ignore:
Timestamp:
Sep 2, 2009, 11:52:02 AM (11 years ago)
Author:
David Fraser <davidf@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@98
Message:

Rather use sound playing (we don't need to stream sound effects from disk), and cache sounds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/sound.py

    r90 r97  
    1616        print >>sys.stderr, "Could not initialize sound system: %s" % exc
    1717
     18SOUND_CACHE = {}
     19
    1820def play_sound(filename):
    1921    """plays the sound with the given filename from the data sounds directory"""
     
    2123        return
    2224    file_path = data.filepath("sounds", filename)
    23     if not os.path.exists(file_path):
    24         return
    25     pygame.mixer.music.load(file_path)
    26     pygame.mixer.music.play()
     25    sound = SOUND_CACHE.get(file_path, None)
     26    if not sound:
     27        if not os.path.exists(file_path):
     28            return
     29        SOUND_CACHE[file_path] = sound = pygame.mixer.Sound(file_path)
     30    sound.play()
    2731
    2832
Note: See TracChangeset for help on using the changeset viewer.