【问题标题】:Ursina Engine texturesUrsina 引擎纹理
【发布时间】:2022-01-02 04:48:12
【问题描述】:

所以我开始使用一个名为 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()   

【问题讨论】:

  • 纹理加载是否正确? sans.png 相对于您的代码位于何处?

标签: python ursina


【解决方案1】:

去做吧:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

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

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

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

      我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-28
        • 2022-08-22
        • 2022-07-12
        • 2022-11-18
        • 2022-01-02
        • 2023-02-14
        • 2021-09-13
        • 2015-06-07
        相关资源
        最近更新 更多