出于某种原因,我的背景不会改变,并且当按下空格键时我的游戏不会启动。我没有收到任何错误,该程序无法正常工作。请帮忙。
def main():
title = games.load_image("contratitle.bmp",transparent = False)
games.screen.background = title
cursor = Cursor()
games.screen.add(cursor)
xd = 0
if games.keyboard.is_pressed(games.K_q):
xd = 1
while xd == 1:
screen = games.load_image("jungle.bmp", transparent = False)
games.screen.background = screen
file2 = 'contra.mp3'
pygame.mixer.music.load(file2)
pygame.mixer.music.play()
rizer = Rizer()
games.screen.add(rizer)
runner = Runner()
games.screen.add(runner)
shooter = Shooter()
games.screen.add(shooter)
spreadpower = Spreadp()
#games.screen.add(spreadpower)
rizerlives = Rizerlives()
games.screen.add(rizerlives)
rizerlivesa = Rizerlivesa()
games.screen.add(rizerlivesa)
#bean = Bean()
#games.screen.add(bean)
games.screen.mainloop()
main()
然后,我尝试使用pygame.display.update(),但这也不起作用。我把它放在错误的地方吗?
def main():
screen = games.load_image("contratitle.bmp",transparent = False)
games.screen.background = screen
cursor = Cursor()
games.screen.add(cursor)
xd = 0
if games.keyboard.is_pressed(games.K_SPACE):
xd = 1
while xd == 1:
screen = games.load_image("jungle.bmp", transparent = False)
games.screen.background = screen
file2 = 'contra.mp3'
pygame.mixer.music.load(file2)
pygame.mixer.music.play()
rizer = Rizer()
games.screen.add(rizer)
pygame.display.update()
games.screen.mainloop()
main()
答案 0 :(得分:2)
对于您的第7行代码:
if games.keyboard.is_pressed(games.K_q):
您似乎需要将其更改为:
if games.keyboard.is_pressed(games.K_SPACE):
有关PyGame游戏键的更多文档,请参阅以下链接: