Pygame函数文本持续3秒

2024-06-01 02:01:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个正在倒计时的游戏,在倒计时结束时,我想在屏幕上显示文本“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

Tags: thetotext文本onglobalactive倒计时
1条回答
网友
1楼 · 发布于 2024-06-01 02:01:49

仅当^{}^{}时,显示才会更新 被称为。此外,您还必须在显示更新在窗口中可见之前^{}处理事件:

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 

相关问题 更多 >