我有一个游戏做倒计时,在倒计时结束时我想显示的文字“小姐走开!”在屏幕上持续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发布于 2020-11-05 15:58:34
只有在调用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 https://stackoverflow.com/questions/64700636
复制相似问题