问题描述
我有一个正在进行倒计时的游戏,在倒计时结束时,我想显示文本“ 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,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()
或pygame.display.flip()
中更新显示
叫做。此外,在窗口中显示更新之前,您必须用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