首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用()在Ursina模块中做什么

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

Stack Overflow用户
提问于 2020-01-29 17:41:56
回答 1查看 1.1K关注 0票数 2

我进口了Ursina module。这是一个游戏引擎。

我查阅了一个教程,在代码中使用了invoke()。我试图找到文档,但似乎没有相关信息。本教程中的代码如下:

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

# create a window
app = 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 game
app.run()

请帮帮我。

我正在使用Linux。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-30 05:04:54

它用于调用带有延迟的函数,类似于联合中的调用()。因此,在这种情况下,在0.25秒后,玩家.y会减少1。

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

编辑:文档中的示例:

代码语言:javascript
复制
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)`
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59972742

复制
相关文章

相似问题

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