首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >暂停函数Ursina - Python

暂停函数Ursina - Python
EN

Stack Overflow用户
提问于 2022-05-19 21:36:27
回答 1查看 238关注 0票数 1

在Ursina中,我试图为我的游戏做一个暂停菜单,我无法了解函数pause()是如何工作的,或者如何实现它。

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-20 17:50:13

暂停已经在ursina中实现。只需将application.paused设置为真或假。application.pause()application.resume()也是这样做的。

代码语言:javascript
复制
from ursina import *


app = Ursina()

# Make a simple game so we have something to test with
from ursina.prefabs.first_person_controller import FirstPersonController
player = FirstPersonController(gravity=0, model='cube', color=color.azure)
camera.z = -10
ground = Entity(model='plane', texture='grass', scale=10)

# Create an Entity for handling pausing an unpausing.
# Make sure to set ignore_paused to True so the pause handler itself can still recieve input while the game is paused.
pause_handler = Entity(ignore_paused=True)
pause_text = Text('PAUSED', origin=(0,0), scale=2, enabled=False) # Make a Text saying "PAUSED" just to make it clear when it's paused.

def pause_handler_input(key):
    if key == 'escape':
        application.paused = not application.paused # Pause/unpause the game.
        pause_text.enabled = application.paused     # Also toggle "PAUSED" graphic.

pause_handler.input = pause_handler_input   # Assign the input function to the pause handler.


app.run()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72311325

复制
相关文章

相似问题

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