python Ursina引擎纹理

cnh2zyt3  于 2023-02-18  发布在  Python
关注(0)|答案(6)|浏览(332)

所以我开始使用一个叫做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()
ux6nzvsh

ux6nzvsh1#

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

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

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

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

我希望这是有帮助的。

anauzrmj

anauzrmj2#

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

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

b4lqfgs43#

就这么办吧:

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

wydwbb8l4#

假设我有一个名为Example.png的纹理,我会包含这样的纹理
纹理=“示例”

ttisahbt

ttisahbt5#

尝试将其放在紧靠py文件的assets文件夹中

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

qgzx9mmu6#

你可以这样做-

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

如果纹理不在文件夹里-

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

还要确保png/texture位于您正在处理的项目文件夹中!

相关问题