5

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()   
Anslip
  • 63
  • 4

6 Answers6

4

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.

Nyctophilla
  • 121
  • 4
2

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')
0

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()   
Tanay
  • 561
  • 1
  • 3
  • 16
0

So let’s say I have a texture called Example.png, I would include the texture like this

texture=“Example”

Chris
  • 1
  • 1
0

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

Sand=Entity(model="quad",texture="assets/sans.png")
Arian
  • 57
  • 9
0

You could do this instead-

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

Or if the texture is not in a folder-

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

Also make sure that the png/texture is in the project folder your working on!