Sys.load_resource paths

#1

How does this work?

if I want to load a PNG from a bundled resource can someone clear up the following because I keep trying and I can’t figure it out.

Assume filename I want to load is: mygraphic.png

Assume directory mygraphic.png is located in will be /bundled/common/mygraphic.png
(common is correct so it works on all platforms yes?)

Where do I put the directory? in main? or outside of it?

What is the path I put in bundled resources in game.project?

What should the path be that I use for sys.load_resource in my code?

0 Likes

#2

You can use sys.get_application_path() to get the path to the application, but it requires special considerations per platform since sometimes it points you to the directory where the exe is and where your mygraphics.png will also be, and sometimes it points you to an .app folder which you must then go into like in macOS. iOS is flat I think.

For game.project you want something like

[project]
...
bundle_resources =  /bundled

sys.load_resource is the wrong thing to use for bundle_resources. If you want to load something with sys.load_resource their folders should be listed under custom_resources, which are included packed inside of the game files. These files are relative to the root of your project. So if you have “/json/myfile.json” that’s the path you would use for loading, and you would want to include the json folder as a custom resource.

Usually you want to use budled resources when you want something outside of the game pack for various reasons such as reducing memory footprint like with FMOD sound banks, or swapable portal splash images.

1 Like

#3

so what works with bundle_resources to load from disk? and how does that work?

To be clear, I want to load one time backgrounds for a scene into memory, use them, discard, and load them from whatever is bundled with the app, or HTML5 package. I had io.open working locally in the editor but not in the HTML5 bundle so I figured it’s a pathing / packaging issue and I’m still struggling to match the combination of approach / file paths / packaging bundles to get it to sync up. I tried Mac package and it fails too. It seems once I understand the specifics of addressing objects in the various directory structures I can fix it all.

0 Likes

#4

The best and easiest solution to work with that is guaranteed to work the same on all platforms is to use sys.load_resource() and the Custom Resources field in game.project. If you use Custom Resources the files will be included in the application archive which means that you can’t read them using io.* operations. On the other hand you don’t have to care about various quirks of the different file systems. sys.load_resource() is guaranteed to work the same way on all platforms.

0 Likes