0

我的 pygame 游戏没有播放声音,我尝试以几种不同的方式播放它。我能得到任何帮助吗?

bif="bg.bmp"
mif="Male Hero.png"

import os, sys
import pygame, sys
from pygame.locals import *

pygame.init()
pygame.mixer.pre_init(44100, -16, 2, 2048)

walk = pygame.mixer.Sound(os.path.join("Walk.wav"))

screen=pygame.display.set_mode((400,400),pygame.FULLSCREEN,32) 
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

x,y=0,0
movex, movey=0,0


while True:
     for event in pygame.event.get():
        if event.type == QUIT:                                                    
            pygame.quit()
            sys.exit
        if event.type == KEYDOWN:
            if event.key == K_a:
               movex=-0.04
               walk.play
            elif event.key==K_d:
                 movex=+0.04
                 walk.play
            elif event.key==K_w:
                 movey=-0.04
                 walks.play
            elif event.key==K_s:
                 movey=+0.04
                 walk.play
            elif event.key==K_ESCAPE:
                 pygame.quit()
                 sys.exit
        if event.type==KEYUP:
             if event.key == K_a:
                movex=0
            elif event.key==K_d:
                 movex=0
            elif event.key==K_w:
                 movey=0
            elif event.key==K_s:
                 movey=0

    x+=movex
    y+=movey

    screen.blit(background,(0,0))
    screen.blit(mouse_c,(x,y))
    pygame.display.update()

这是我的整套代码,这里是应该播放声音的部分。

while True:
for event in pygame.event.get():
    if event.type == QUIT:                                                    
        pygame.quit()
        sys.exit
    if event.type == KEYDOWN:
        if event.key == K_a:
           movex=-0.04
           walk.play
        elif event.key==K_d:
             movex=+0.04
             walk.play
        elif event.key==K_w:
             movey=-0.04
             walks.play
        elif event.key==K_s:
             movey=+0.04
             walk.play

你能帮忙的话,我会很高兴。

4

1 回答 1

3

我相信您需要更改walk.playwalk.play()修复您拥有的错字walks而不是walk:)

于 2013-08-20T17:47:13.770 回答