简体   繁体   English

Ursina 引擎纹理

[英]Ursina Engine textures

So I started playing with an API for python called Ursina Engine and I got to the point I need to add a texture.因此,我开始使用名为 Ursina 引擎的 python 的 API 并达到需要添加纹理的地步。 Whatever I put for the file path, always just doesn't render.无论我为文件路径放置什么,总是不会渲染。 No errors, just a blank entity.没有错误,只是一个空白实体。

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

Your code should work but if it doesn't you probably haven't loaded the texture properly.您的代码应该可以工作,但如果不能正常工作,您可能没有正确加载纹理。 If it's located in a file called 'textures' for example, your code should be something like this:例如,如果它位于一个名为“纹理”的文件中,您的代码应该是这样的:

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

But if it still doesn't work, you can try this:但如果还是不行,你可以试试这个:

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

I Hope this is helpful.我希望这是有帮助的。

Probably the texture isn't loaded correctly, to load it correctly you can try to copy paste the image link, for example:可能纹理没有正确加载,要正确加载它,您可以尝试复制粘贴图像链接,例如:

sand = Entity(model = 'quad', texture = 'C:/Users/guest/Pictures/sans.png')

Just do it:去做就对了:

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

So let's say I have a texture called Example.png, I would include the texture like this所以假设我有一个名为 Example.png 的纹理,我会包含这样的纹理

texture=“Example”纹理=“示例”

Try putting it in an assets folder just next to the py file尝试将其放在 py 文件旁边的资产文件夹中

Sand=Entity(model="quad",texture="assets/sans.png")

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

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