首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >游戏函数文本3秒

游戏函数文本3秒
EN

Stack Overflow用户
提问于 2020-11-05 15:49:42
回答 1查看 367关注 0票数 1

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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-05 15:58:34

只有在调用pygame.display.update()pygame.display.flip()时才更新显示。此外,还必须通过pygame.event.pump()处理事件,然后才能在窗口中看到显示的更新:

代码语言:javascript
复制
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 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64700636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档