为了账号安全,请及时绑定邮箱和手机立即绑定

在 Ursina 模块中调用()做什么

在 Ursina 模块中调用()做什么

慕桂英4014372 2022-07-12 10:23:05
我导入了Ursina模块。它是一个游戏引擎。我查了一个教程,并在代码invoke()中使用了。我试图找到文档,但似乎没有关于它的信息。教程中的代码如下所示:from ursina import *# create a windowapp = Ursina()# most things in ursina are Entities. An Entity is a thing you place in the world.# you can think of them as GameObjects in Unity or Actors in Unreal.# the first paramenter tells us the Entity's model will be a 3d-model called 'cube'.# ursina includes some basic models like 'cube', 'sphere' and 'quad'.# the next parameter tells us the model's color should be orange.# 'scale_y=2' tells us how big the entity should be in the vertical axis, how tall it should be.# in ursina, positive x is right, positive y is up, and positive z is forward.player = Entity(model='cube', color=color.orange, scale_y=2)# create a function called 'update'.# this will automatically get called by the engine every frame.def update():    player.x += held_keys['d'] * time.dt    player.x -= held_keys['a'] * time.dt# this part will make the player move left or right based on our input.# to check which keys are held down, we can check the held_keys dictionary.# 0 means not pressed and 1 means pressed.# time.dt is simply the time since the last frame. by multiplying with this, the# player will move at the same speed regardless of how fast the game runs.def input(key):    if key == 'space':        player.y += 1        invoke(setattr, player, 'y', player.y-1, delay=.25)# start running the gameapp.run()请帮我。PS我正在使用Linux Mint。
查看完整描述

1 回答

?
郎朗坤

TA贡献1921条经验 获得超9个赞

它用于延迟调用函数,类似于 Unity 中的 Invoke()。所以在这种情况下,它会在 0.25 秒后将 player.y 减少 1。


调用(函数,*args,**kwargs)


编辑:文档中的示例:


def test_func(item, x=None, y=None):

    print(item, x, y)


test_func('test')

invoke(test_func, 'test', delay=.1)

invoke(test_func, 'test1', 1, 2, delay=.2)

invoke(test_func, 'test2', x=1, y=2, delay=.3)`


查看完整回答
反对 回复 2022-07-12
  • 1 回答
  • 0 关注
  • 231 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信