How do you work Pygame?

Hey, I just downloaded the Pygame files, because I want to use it for sound in a game I’m making in Blender 2.49b, and I haven’t got a clue how to work it, I know it needs to be in the same folder as the game, but other than that I know nothing, will it be possible to run the sound with a blender actuator? So if someone could explain to me how to set up a little scene so that when the player presses W it plays a walking sound, if you could just explain this setup to me then I will be able to figure out other stuff myself. Thanks for any help you might be able to give me. :slight_smile:

You need to run it using python.

I forget the specifics, but use pygame.mixer:

You import the pygame modules into a python script that same why you would use any other external module. You don’t need to use the sound actuator as the sound will be controlled entirely by python and not blender. You would only need to include the pygame files in the blend folder if you were packing it to be used on other computers without pygame. For the set up you requested you can use something like this (with a keyboard sensor looking for the W key attached to the script):

import pygame.mixer

cont = GameLogic.getCurrentController()
own = cont.owner

W = cont.sensors["W_KEY"]

def play_mp3(sound_file):


if W.positive:

Note: this only works with MP3’s using a special channel in the pygamel.mixer for streaming MP3’s, to use WAV or OGG you would probably have to use another method loading the sound file into memory (there are a few ways pygame can handle sound obejcts).

Hope this helps!