嗨大家好
第一次在板上发文,想问一个关于用pygame写游戏时,在放音乐时的问题
我把我的游戏分成许多套件组合,其中一个套件写了有关播放音乐的设定,如下:
class Settings():
def music(self):
self.pygame.init()
self.pygame.mixer.init()
self.screen=pygame.display.set_mode([800,600])
self.soundwav=pygame.mixer.Sound("Mr_Tea.ogg")
self.soundwav.play()
while 1:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
最后把套件组合在一起后,我写了以下的指令(可以先忽略其他套件谢谢> <)
import pygame
from settings import Settings
from ship import Ship
import game_functions as gf
from pygame.sprite import Group
from game_stats import GameStats
from button import Button
from scoreboard import Scoreboard
def run_game():
pygame.init()
pygame.mixer.init()
ai_settings =Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,
ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
#创建Play按钮
play_button = Button(ai_settings, screen, 'Play')
#创建游戏统计信息实例
stats = GameStats(ai_settings)
#创建记分牌
sb = Scoreboard(ai_settings, screen, stats)
ship = Ship(ai_settings, screen)
bullets = Group()
aliens = Group()
gf.creat_fleet(ai_settings, screen, ship, aliens)
while True:
gf.check_events(ai_settings, screen,stats, sb, play_button, ship,
aliens, bullets)
if stats.game_active:
ship.update()
gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
bullets)
gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
bullets)
gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
bullets,
play_button)
run_game()
除了音乐放不出来外,所有都能正常执行,也没有显示任何error,想请问这到底是怎么
回事?感谢各位大神了!