Not sure if anyone else is interested, but I had this problem, too, because until I solve my problem with Spine support, I'm having to load a lot of images for my high-res animations. I didn't like Android thinking the app stopped responding and I wanted a more accurate feedback for how far along the loading is...
So my solution was to devise a method of background pre-loading which also serves my purpose of a progress bar.
Testing on my Nexus 4, I can load approximately 15 images per second (these are high res, so most of you should probably get better results than that). So, essentially what I do is throttle my loading by loading 1 or more images per frame and call Sync() each frame.
I load up everything I need for Level 1 on the Title Screen so any sort of delay in the user pressing "Play" will be exploited for pre-loading. If they press "Play" I kill the throttle and load at maximum rate, which kills the FPS but the only thing updating is the progress bar anyway. This is just my preference.
Transitioning levels will be an "artform" on what needs to be preloaded and what can wait so that you stay optimized on memory usage, but likely a lot of stuff will be reused from one level to the next ( ie. the player images ).
Alright, so enough about that. I've included the 'library' of functions, commented sufficiently I hope, in the post
as an attachment and the following code are the code dependencies for the library to work:
Type _Image
Image as Integer
Path as String
EndType
#include "image_registry.agc"
#constant C_NUM_IMAGES <A large enough number to cover however images you think will need to be loaded at any one time, I personally use 1024>
global dim g_Image_Registry[C_NUM_IMAGES] as _Image
The library allows you to replace
EVERY call to LoadImage() with the function ImageRegistry_GetImage(Path as String). There will be no duplicate loads of the same file.
What's nice is that you can do something like:
ImageRegistry_Add("/media/Company/Backdrop.png")
ImageRegistry_Add("/media/Company/Copyright.png")
ImageRegistry_Add("/media/Company/Logo.png")
ImageRegistry_Add("/media/Company/Presents.png")
CreateSprite(1, ImageRegistry_GetImage("/media/Company/Backdrop.png"))
CreateText(1, "Pre-Load Progress: ")
do
for I = 1 to C_NUM_IMAGES
if ImageRegistry_Load(I) then I = C_NUM_IMAGES + 1
next I
SetTextString(1, "Pre-Load Progress: " + Left(Str(ImageRegistry_GetLoaded() / ImageRegistry_GetTotal() * 100.0), 4) + "%")
Sync()
loop
You can add a time delay to that for loop to throttle the loading a bit ( if you need more responsiveness on a menu or something. ) You have the option to force the condition for a pre-load complete before moving to your next scene, or not. The pre-load idea is just simply exploit idle time to reduce further load time the player might experience.
I'm sure there could be a more elegant solution, but this has worked for me wonderfully.
In fact, I'm pretty curious if anyone has any comments. Positive or negative. Also, if anyone ends up using it in some fashion, let me know how it's worked for you and if you made any adjustments
[b][i]