完整代码和文件:https://www.dropbox.com/sh/gqke6hfooz7mbnr/Qm8NMlyNqc
似乎无法找到解决这种困境的方法。基本上我按空格转到下一个循环(levelTwo
)它就停止了,即使我有代码这样做,屏幕上也没有新内容。我非常感谢你的帮助。
部分代码可能存在困境,但不确定:
if len(rabbits) == 0:
rabbitCounter = 0
windowSurface.blit (textLevelOne, (100, 104))
levelOne = False
windowSurface.fill((0,0,0))
#Ritar fönstret
pygame.display.update()
mainClock.tick(60)
#LEVEL TWO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
startSoundLevelTwo = True
while levelOne == False:
levelTwo = True
if startSoundLevelTwo == True:
rabbitSound.play()
foxSound.play()
pygame.mixer.music.play()
startSoundLevelTwo = False
pigSpawn = True
boarSpawn = True
答案 0 :(得分:1)
2级缺少pygame.display.update()
电话。
就个人而言,我喜欢用一个主循环来构造pygame代码,如下所示:
level = 1
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# Process event, update game state:
if level == 1:
# Update level 1 state
elif level == 2:
# Update level 1 state
# Clear screen:
windowSurface.fill((0,0,0))
# Draw current state to screen:
if level == 1:
# Play level 2 music
# Draw level 1 state to screen
elif level == 2:
# Play level 2 music
# Draw level 2 state to screen
...
# Update screen and control FPS
pygame.display.update()
mainClock.tick(60)
您可以为每个级别使用函数,因此您可以简化主循环。