我的程序的目标是循环图像并将它们显示在屏幕上。当用户按下空格键时,它应该进入一个新屏幕。出于某种原因,从用户按下空格键到退出 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
我该如何解决?