Pygame功能文字3秒

Pygame function text for 3 seconds

我有一个游戏正在倒计时,在倒计时结束时我想显示文字“Missle Away!”在屏幕上停留 3 秒钟。我有下面的代码,但是当我 运行 它时,文本永远不会显示。如果我删除延迟,文本会显示,但当然它不会在 3 秒后消失。

def missle_call():
    global missle_active
    global active
    while missle_active == True:
        gameDisplay.blit(radarbg, (700, 100)) # clears the countdown text by writing the background image over it
        TextSurf, TextRect = big_text_objects("Missle Away!" , large_base_font) # set font & text 
        TextRect.center = (950, 300) # set location of text 
        gameDisplay.blit(TextSurf, TextRect) # render text to screen 
        pygame.time.delay(3000) # continue to show text on screen for 3 seconds 
        gameDisplay.blit(radarbg, (700, 100)) # cover text on display by blitting the background image on it 
        active = False # reset the launch execution to not launched 
        return

    else:
        return

仅当 pygame.display.update() or pygame.display.flip() 叫做。此外,在显示更新在 window:

中可见之前,您必须通过 pygame.event.pump() 处理事件
gameDisplay.blit(TextSurf, TextRect) # render text to screen 
pygame.display.flip()
pygame.event.pump()
pygame.time.delay(3000) # continue to show text on screen for 3 seconds