Loading assets?

Community Forums/Monkey2 Talk/Loading assets?

Richard Betson(Posted 2016) [#1]
Hi,

I have several assets to load and I use configuration text files that lists them all. I cant #Import these assets (images and data for the most part) as their locations are in a text file and those locations and file names may be modified. So how do I load assets without using #Import?

Thanks.

Edit - Just noticed this thread. Might have answer. Maybe. http://www.monkey-x.com/Community/posts.php?topic=10597


Richard Betson(Posted 2016) [#2]
Well, I can load an image if I use the entire file path but only if I use the whole path ie: "/home/mycomputer/Programming/monkey2/phoenix/assets/ship.png". Using "assets/ship.png" (my build directory is in "/home/mycomputer/Programming/monkey2/phoenix/") wont work with the file system and Image.Load(). Maybe a Linux thing? I've tried variations like "assets/ship.png" , "/assets/ship.png" , "./assets/ship.png" but still cant get it to load that way. Do I have to use the entire file path and name?


dawlane(Posted 2016) [#3]
I think that the trick here would be for the executable to find it's own location first (App Path) and construct a path based on that for loading assets via LoadImage etc.
Don't for get that your assets directory must be in the same location as where the executable would end up when you build and run.


Richard Betson(Posted 2016) [#4]
I would like to see MX2 use the MX1 approach to assets in that I could put them all in one folder and they would be copied to an assets build folder. That's the dream anyway. :)


therevills(Posted 2016) [#5]
Currently MX2 will only copy the resources which are defined as an "Import", eg:
#Import "assets/spaceship.png"

Then you can load it like this:
Field image:Image
...
image = Image.Load("asset::spaceship.png")