0

我的程序的目标是循环图像并将它们显示在屏幕上。当用户按下空格键时,它应该进入一个新屏幕。出于某种原因,从用户按下空格键到退出 game1 循环之间存在延迟。

def game_loop1():
        game1=True
        winScreen=True
        current=0
        myfont = pygame.font.SysFont("monospace", 25)
        label = myfont.render("Who is this person? (Press Space)", 1, (0,0,0))


    while game1:
            for event in pygame.event.get():

                if event.type == pygame.QUIT:
                   pygame.quit()
                if event.type == pygame.KEYDOWN:
                    if event.key==pygame.K_SPACE:
                       game1=False # doesn't break out of loop immediately here
        gameDisplay.fill(white)
        gameDisplay.blit(label,(0,500))
        gameDisplay.blit(obama[current], (0,0))
        current+=1
        pygame.display.flip()
        clock.tick(50)
        pygame.time.delay(2500)


    while winScreen:
        gameDisplay.fill(white)
        winLabel=myfont.render("The person was Obama! ", 1, (0,0,0))
        gameDisplay.blit(winLabel,(0,500))
        gameDisplay.blit(obama[len(obama)-1], (0,0))
        pygame.display.flip()
        pygame.time.delay(2500)
        winScreen=False 

我该如何解决?

4

1 回答 1

0

你可以试试:

game1=False
break

立即退出 while 循环。

但是,在这种情况下,您实际上并不需要该game1变量。您可以将循环条件更改为True,并将该行替换为game1=Falsebreak您的代码应该可以按预期工作。

于 2016-10-24T15:17:55.090 回答