Load bundled .svg files (SOLVED)

I store .svg files in games/svg/. They can’t be added to the actual collection, so I bundle them separately when building the project. I’ve added them to bundle_resources/web/game/svg/ and they’re copied into this folder on export to HTML5.

Loading them doesn’t work, however, so the question is: How do I access the bundled files? I may be missing something basic here, so bear with me!

How are you loading them?

I’m using io.load, and now that you said that, I should really be using sys.load_resource, should’t I? :thinking:

Aside from that, is duplicating the files like I am the “right” way of doing it?

Using sys.load_resource I get an error: /Users/niclasaberg/Bitbucket/Test/Defold/game/svg (Is a directory)

With these settings:

57

05

Directories should be fine, right?

No, sys.load_resources() is for resources bundled using the Custom Resources field in game.project. Resources put in Custom Resources will be included in the game archive (ie not as individual files on disk), and you read them using sys.load_resource().

io.open() and io.read() should be used when loading from filesystem. The root directory would be the location of the exe and you work from there. If you want files to be copied into your application bundle (ie inside the apk, ipa, app or the target folder when bundling for windows, linux and html5) you use Bundle Resources and the folder structure mentioned in the documentation.

Do note that the Bundle Resources will only be copied when you Bundle the application. When you do Project->Build the files will not be copied.

1 Like

I’d probably use Custom Resources in your case actually.

1 Like

YES! It works. The final stumbling block was the formatting of the paths.

This doesn’t work:
05

This works:
53

It looks like “Bundle Resources” and “Custom Resources” have to be formatted differently to work.

1 Like

Yes, this is a bit unfortunate to be honest… Created DEF-3748 to investigate why custom resources must not start with a forward slash.

3 Likes

It is also a bit annoying that in the game.project I specify assets/definitions as a custom resource but I need to load it like sys.load_resource("/assets/definitions/file.json")

In the project it shouldn’t start with a slash but when loading the file it have to.

4 Likes

@Mattias_Hedberg please add this info to the ticket if you have the time!

1 Like