Embedded vs external assets: How to load an asset that was added/renamed at runtime?

207 views
Skip to first unread message

Igor S.

unread,
Mar 21, 2016, 12:36:07 PM3/21/16
to HaxeFlixel
Hi,

I have a project with a fellow artist, that is build upon HaxeFlixel. He needs to modify assets (change, add, rename, remove files) without recompilation, just like modding the game.
We aim for native targets (using neko at the moment), and the assets are in the directory beside the executable.
I have a .json file that specifies what image to load. If there wasn't such an image file at compilation time, Assets class fails to load it, even if it's present. To fix I need to compile again.

Is there a way to load any file from the assets directory, yet preserving Assets class file caching functionality?

Ashiq A.

unread,
Mar 21, 2016, 11:29:30 PM3/21/16
to haxef...@googlegroups.com
Yes. I do exactly this for one of my current in-development games. I have similar requirements to yours (assets specified in a JSON file, reload at runtime, debugging on Neko).

Calling "lime update project.xml neko" will reload the assets into that directory.



--
HaxeFlixel Development Community
See our github https://github.com/haxeflixel/ and our documentation http://haxeflixel.com/documentation/
---
You received this message because you are subscribed to the Google Groups "HaxeFlixel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haxeflixel+...@googlegroups.com.
Visit this group at https://groups.google.com/group/haxeflixel.
To view this discussion on the web visit https://groups.google.com/d/msgid/haxeflixel/7298a1a6-f721-4b3f-b56f-dbb8f62933d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Igor S.

unread,
Mar 23, 2016, 3:04:40 PM3/23/16
to HaxeFlixel
Thanks, I'll try this soon!

Igor S.

unread,
Mar 24, 2016, 3:01:47 PM3/24/16
to haxef...@googlegroups.com
So "lime update" is one of the steps of "lime test". If I get it correctly, asset cache on neko target is stored in "manifest" file.
Is there a possibility to update to the same folder (i.e. rebuild the cache having neko build + Project.xml), for simplicity on the artist's side?

You received this message because you are subscribed to a topic in the Google Groups "HaxeFlixel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/haxeflixel/icCdxAZ5wRM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to haxeflixel+...@googlegroups.com.

Claudio Ficara

unread,
Mar 24, 2016, 3:26:06 PM3/24/16
to HaxeFlixel
Here's something that I do, to dinamically load a .TMX file (a Tiled level). This way, I open my game, edit the level, save the level, and I can reload it again, without closing the game. Is great.

source = new Fast(Xml.parse(File.getContent("../../../../" + data)));

This won't work on flash or html5 targets I believe, since has to read file system. If not mistaken, you can do a similar thing on your Graphic property for your sprite, and it would load it from file system, that is, your hard drive. Alternatively as Ashiq said, you can also have a global .xml file with indexes to the data stored on file system if you wish.

Ashiq A.

unread,
Mar 24, 2016, 4:27:24 PM3/24/16
to haxef...@googlegroups.com
I don't know about the manifest file. When you run "lime build," it copies the assets folder to bin\neko\linux64 (or whatever the path is with the executable).

The exact command I use in my project, from the context of the executable directory, is "lime update ../../../../Project.xml neko".  On neko, this will copy any new assets from the original (source) folder to the correct (bin) folder, and do whatever it needs for the (currently running) project to be able to access the new/changed assets.


Igor S.

unread,
Mar 26, 2016, 5:08:17 AM3/26/16
to haxef...@googlegroups.com
@Claudio, yes, I've already done that in #ifdef for native targets. What I worried about is reinventing the wheel for caching files: when I request the same file several times, I want it to be loaded from memory, like Assets. Though, since your approach allows for live reloading, it's better for productivity, and I think I'll keep it (implementing the cache myself where needed).
@Ashiq, to my surprise, just copying files is not suffice, if messing with filenames (add or rename file). And having two asset folders at artist's side is error prone (I know him ;-)).

Ashiq A.

unread,
Mar 26, 2016, 6:56:41 AM3/26/16
to haxef...@googlegroups.com
@Igor you don't need to worry about the generated copy. Tell your artist to:

- Use the assets folder in the source directory
- Run "lime update project.xml neko" from the source directory

That should be enough.

I embedded the reloading in the app. In the context of where it runs, you need to tell it where the project.xml file is, so you need to know where the generated binary is.

Igor S.

unread,
Mar 27, 2016, 11:26:13 AM3/27/16
to haxef...@googlegroups.com
Thanks, guys, I think I got the idea!

Igor S.

unread,
Apr 10, 2016, 4:06:58 PM4/10/16
to HaxeFlixel
As it turns out, I can mix built-in caching assets with manual file loading like this:

    function LoadBitmap(path: String): BitmapData
   
{
        trace
("loading bitmap from: " + path);
#if !desktop
       
return Assets.getBitmapData(path);
#else
       
if (FlxG.bitmap.checkCache(path))
           
return FlxG.bitmap.get(path).bitmap;
       
else
       
{
           
var bytes = ByteArray.readFile(Path.join([Path.directory(Sys.executablePath()), path]));
           
return FlxGraphic.fromBitmapData(BitmapData.loadFromBytes(bytes), false, path, true).bitmap;
       
}
#end
   
}

Cheers!



Reply all
Reply to author
Forward
0 new messages