2

所以我开始使用一个名为 Ursina Engine 的 Python API,我到了需要添加纹理的地步。无论我为文件路径放置什么,总是不会渲染。没有错误,只是一个空白实体。

    from ursina import * # import everything we need with one line.
#an entity is basically anything you can see or hear/interact on a screen

def update():#updtes every frame
    if held_keys['a']:
        test_square.x -= 1 * time.dt #so the .x is the axis (you can use y too and -= minuses every frame), multiplying it by time.delta means it will move in accordance with the framerate
    # time.dt is the completion time between the last frame
    if held_keys['d']:
        test_square.x += 1 * time.dt
app = Ursina()

test_square = Entity(model = 'quad', color = color.red, scale = (1,4), position = (3,1))#x then y for scale and pos

sans_texture = load_texture('sans.png')
sand = Entity(model = 'quad', texture = sans_texture)

app.run()   
4

3 回答 3

2

您的代码应该可以工作,但如果不能正常工作,您可能没有正确加载纹理。例如,如果它位于一个名为“纹理”的文件中,您的代码应该是这样的:

sans_texture = load_texture('textures/sans.png')
sand = Entity(model = 'quad', texture = sans_texture)

但如果还是不行,你可以试试这个:

sand = Entity(model = 'quad', texture = 'textures/sans.png')

我希望这是有帮助的。

于 2021-11-27T10:59:59.393 回答
1

可能纹理没有正确加载,要正确加载它,您可以尝试复制粘贴图像链接,例如:

sand = Entity(model = 'quad', texture = 'C:/Users/guest/Pictures/sans.png')
于 2021-11-28T14:32:35.763 回答
0

去做就对了 :

from ursina import * # import everything we need with one line.
#an entity is basically anything you can see or hear/interact on a screen

def update():#updtes every frame
    if held_keys['a']:
        test_square.x -= 1 * time.dt #so the .x is the axis (you can use y too and -= minuses every frame), multiplying it by time.delta means it will move in accordance with the framerate
    # time.dt is the completion time between the last frame
    if held_keys['d']:
        test_square.x += 1 * time.dt
app = Ursina()

test_square = Entity(model = 'quad', color = color.red, scale = (1,4), position = (3,1))#x then y for scale and pos

sand = Entity(model = 'quad', texture = 'sans.png')

app.run()   
于 2021-12-31T16:43:37.123 回答