Ursina Engine textures

Viewed 670

So I started playing with an API for python called Ursina Engine and I got to the point I need to add a texture. 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()   
5 Answers

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

texture=“Example”

Try putting it in an assets folder just next to the py file

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