简体   繁体   English

如何在Pygame中制作一个暂停屏幕?

[英]How to make a pause screen in Pygame?

I want to make a function where when I press p the game stops and shows "Game Paused". 我想创建一个函数,当我按p时游戏会停止并显示“ Game Paused”。

Any help? 有什么帮助吗?

I suggest adding a is_paused boolean flag and add if not is_paused inside your update method to act accordingly (The update method is the method that is executed 30 times per second in your game): 我建议添加一个is_paused布尔标志,并在update方法中添加if not is_paused以采取相应的措施( update方法是每秒在游戏中执行30次的方法):

Some pseudocode: 一些伪代码:

def update(screen, entities, is_paused):
    if is_paused:
        if is_clicked_button(BUTTON_TO_UNPAUSE):
            is_paused = False
        return
    # Logic on screen, entities and so on...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM