Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difficulties with sprite texture import #731

Open
DustanBower opened this issue Oct 23, 2024 · 2 comments
Open

difficulties with sprite texture import #731

DustanBower opened this issue Oct 23, 2024 · 2 comments

Comments

@DustanBower
Copy link

DustanBower commented Oct 23, 2024

I have some tests I'm running with pytest, and they don't load my sprites. I've checked and double-checked the paths and everything, so I started debugging ursina internal code.

If I run the program normally, it initializes my game object, with all the setup code, and it loads the sprite textures fine.

If I run a test that imports the game object and runs it, it does not load the sprite texture files.

I'm creating a Sprite object, which is calling load_texture() with no path, the name of the file (with no file extension). I see no difference between os.getcwd() whether I run the program directly or via pytest.

Figuring it was some sort of path thing, I set asset_folder manually, but no matter when I call it, load_textures() does not demonstrate the change if I run code via pytest. If I try to set the asset_folder manually at the earliest entry point, load_textures() still doesn't see the change in its folders

If I move the setting of the folders variable inside load_textures(), it works fine.

def load_texture(name, path=None, use_cache=True, filtering='default'):
    if textureless:
        return None

    if use_cache and name in imported_textures:
        return copy(imported_textures[name])

    folders = [ # folder search order
        application.compressed_textures_folder,
        application.asset_folder,
        application.internal_textures_folder,
    ]
    _folders = folders
 

I'm not sure why it was set on file initialization to begin with, so I don't know the full implications of moving it, but it resolves the issue I was having, at least.

@pokepetter
Copy link
Owner

I wanted the search order to be customizable by setting texture_importer.folders. However, since the list is created on module import, it can be incorrect if application.asset_folder is changed after that. I assume this is the source of your problem. I've now changed all the importers to behave the same way (textures, models, etc.) and made sure it uses updated paths each time the function is called. The upside to this is that modifying the paths in the application.py module will just work. The downside is that the folder search order won't be documented since it's inside the function now. However, I don't think that's a huge issue compared to asset loading breaking.

Could you see if your code works with the recent change or not? (Install from GitHub, not PyPi)

@DustanBower
Copy link
Author

DustanBower commented Nov 1, 2024

The issue I was having appears fixed in the new version. I can hear music and see one of my sprites, which should be enough to confirm that it's working.

I'm hedging because I seem to have some sort of incompatibility with the new version that is causing walls to be drawn over 80 to 90% of the game, which limits my visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants