python - 如何在 Ursina Python 游戏引擎中添加延迟

标签 python ursina

我最近开始使用 Ursina 游戏引擎(在 Python 中运行),并且在我的许多项目中遇到了问题。我不知道如何实现延迟,或在函数之间休眠。有一个 Wait 函数我无法使用。我尝试过诸如 time.sleep() 之类的替代方案并具有使用延迟的函数,但它们似乎都不起作用。由于这不是一个非常流行的游戏引擎,因此在线指南或有用信息并不多。

Wait function documentation

最佳答案

延迟调用函数是通过使用 invoke() 函数来完成的,如下所示:

def foo():
    print('bar')
    
invoke(foo, delay=5) # Calls myFunc after 5 seconds

对于需要参数的函数:

def foobar(foo, bar):
    print(foo + bar)
    
invoke(Func(foobar, 'foo', 'this is foo\'s value', 'bar', 'and this is bar\'s'), delay=5)

关于python - 如何在 Ursina Python 游戏引擎中添加延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64027162/

相关文章:

python - 当我尝试在 Python 上使用 Ursina 时出现黑屏

python - 如何使用 Ursina 实现敌人碰撞并更改 Ursina 中的子弹方向?

python - 高效简洁的GroupBy扰列透传

python - 如何将 Python2 中的 file() 函数改编为 Python3 函数?

Python 网页抓取教程。连接MySQL数据库问题

python - Ursina Python 引擎 : Lighting, 阴影和光晕效果

python - 如何在 Python 中将两个元素写入一行

python - Python 中奇怪的时间问题

python - 在 Ursina 中使用鼠标正确关闭窗口