Is there a way to determine wether an asset has already been loaded?
-
Is an Asset Loaded?
Actually, this is a bit more complicated. Consider the following code:
package; import kha.Assets; import kha.System; class Main { public static function main() { System.start({title:"TestKha", width:512, height:384}, function(_) { Assets.loadBlobFromPath("blob.res", function(blob) { if(blob != null) trace("Loaded!"); // This works! }); Assets.loadBlobFromPath("blob.res", function(_) { if(Assets.blobs.blob_res != null) trace("Loaded!"); // This doesn't! }); }); } }
It seems a bit weird that the second example doesn't work, but it doesn't. Can anyone explain?
-
Is an Asset Loaded?
I guess, from what you've said, that the load...FromPath() functions can load any file in the file system (almost, I guess!). That is interesting to know, as I was about to ask about expansion packs downloaded from a server and placed somewhere in a user's home, and how to access them.
It is also interesting to know that the loadBlob(), loadImage(), ... functions also set the Assets.blobs.myblob, Assets.images.myimage, ... values before the callback is called.
Can you explain the Assets.blobs.myblob.unload() function? Is it executed immediately? Does it reset the Assets.blobs.myblob value immediately?
-
Is an Asset Loaded?
For some reason, the unload() functions don't work for me. That's why I asked, to try to learn a bit more about their behaviour. After a few tries, I discovered I have to do
Reflect.callMethod(Assets.blobs, Reflect.field(Assets.blobs, name + "Unload"), []);
to get the results I need.
-
Is an Asset Loaded?
Well, I'm unloading some files (one by one) in their onLoad1 callback, and shortly afterwards, in the same callback, I'm reloading them again (with a new onLoad2 callback). Then, I'm unloading them again in this new callback. lol I suppose this is a bit confusing, but it works fine. I need to do this, for some sets of files, every time the app starts, to build (at the end of the first callback) and populate (somewhere in the second callback) a data structure per set of files, needed for the app to work. Only when these data structures are built and populated, can those sets of files be used normally in the regular course of the app. I can't use loadEverything because there are lots of files in the project, but, if I could, it would make things easier.
-
Is an Asset Loaded?
I'm not sure I know too. In the onLoad1() and onLoad2() functions I mentioned, when I do
Assets.blobs.get(name).unload();
it doesn't work. When I do
Reflect.callMethod(Assets.blobs, Reflect.field(Assets.blobs, name + "Unload"), []);
it works. Inside the onLoad1() and onLoad2() callbacks, I can correctly ask if an asset is or isn't loaded (by saying Assets.blobs.get(name) != null) using this last way of unloading, but not the first.
-
Is an Asset Loaded?
.unload()
will unload resource, but not setAssets.blobs.name
tonull
.Unload()
will unload resource and set it tonull
. Beware thanUnload
functions doesn't work with reflection + DCE anymore, only with direct field access (as Robert shows), so you better to use this code:Assets.images.get("foo").unload(); Reflect.setField(Assets.images, "foo", null);
This is exactly what
fooUnload
function do.
Also, i think we can addAssets.load/unload(name:String, onload, onerror)
functions instead ofLoad/Unload
with similar implementation inside.