简体   繁体   English

暂停函数 Ursina - Python

[英]Pause Function Ursina - Python

I'm trying to do a pause menu for my game in Ursina Engine and I can't fount informatino how the function pause() works or how to do it.我正在尝试在 Ursina Engine 中为我的游戏制作暂停菜单,但我无法找到有关函数 pause() 的工作原理或操作方法的信息。

Can someone help me?有人能帮我吗?

Pausing is already implemented in ursina. ursina 中已经实现了暂停。 Just set application.paused to True or False.只需将application.paused设置为 True 或 False。 application.pause() and application.resume() does the same. application.pause()application.resume()做同样的事情。

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()

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

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