I posted the following on Reddit, and I was advised to post here…
I am trying to understand how to load data from files into Amethyst. Specifically, I need to load a PNG file to create a texture.
I am getting a message:
[DEBUG][amethyst_assets::loader] "renderer::Texture": Loading asset "texture/texture.png" with format "PNG" from source "[default source]" (handle id: Handle { id: 7 })
thread 'main' panicked at 'Tried to fetch a resource, but the resource does not exist.
I am basing my code on the Pong tutorial and other examples in Amethyst on GitHub.
Please tell me
- what I should use for the asset directory in the call to Application::build and
- where I should put my asset file assuming the file is called texture/texture.png in the call to loader.load. The error message just tells me “[default source]” — from where? If I had the file path that it is trying to read, I could move the file there.
I am in debug mode at the moment, so the executable will be $WKSP/target/debug/$PROG (i.e. the program is in a workspace — does this affect things?)
I have looked at the book, the API reference and the examples on GitHub, and I cannot work out what to do. I have tried putting the PNG in every location that I can think of, but the app keeps telling me that it cannot find the file (and it does not tell me where it is looking). It seems that I need to set the location of the assets directory, but even setting that explicitly does not help.
My app is part of a workspace, but I have tried creating an assets directory at (a) the workspace level and (b) the app level, and neither of those works.
I have added my specific details to an existing Stack question at https://stackoverflow.com/questions/52019501/amethysts-loader-cant-find-an-asset-file
Also, a related question: is there some way that I can supply the data as a byte array instead of a file? Then I could incorporate the data into my app’s executable using a crate like rust_embed.
The original Reddit post is at https://www.reddit.com/r/rust_gamedev/comments/bjr5s8/how_do_i_load_a_png_into_my_amethyst_game/ [this is a cross-post].