微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pygame功能文字3秒

如何解决pygame功能文字3秒

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。