Re: Getting started with coding audiogames in Python?
magurp244 wrote:
Adding audio can be fairly straightforward, but where and how complex it is can depend on a number of factors and personal tastes. Here's an example of how to add audio to a Pygame framework:
import pygame from pygame import mixer import sys def Example(): #initialize pygame pygame.init() #initialize sound mixer mixer.init() #create display window = pygame.display.set_mode([640,480]) #load sound sound = mixer.Sound('tone5.wav')
#main update loop while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: #if space is pressed, play sound if event.key == pygame.K_SPACE: sound.play() #if escape is pressed, quit if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit(0) #update window pygame.display.update() Example()Keep in mind that Pygame and Pyglet typically only handle basic audio, if you want advanced audio like HRTF, EFX, or 3D positional audio you'll need to use a library like OpenAL, such as with my examples. I have provide other examples for Pyglet, or another Pygame example using OpenAL, if you prefer.
Thank you for the quick reply! This is helpful.
What kind of basic audio do the libraries like pygame and pyglet provide?
Thanks again.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector