Load images in the background while still running lua code (like Xcode loading thread)

The biggest disadvantage of Corona vs. Xcode (for us) is the problem with loading lots of images.
In Xcode we can load these images into the memory while we can still animate e.g. a scene.

In Corona this is not possible, there are always times where nothing happens because the images are loaded at this time and no interactivity is possible.

It would be very important to have an mechanism like this:

  1. declare image varibale e.g. local myImage
  2. myImage = loadImageAsThread(“spriteSheet.png”, onLoaded = imageLoadedListener) into the variable
  3. As soon as the image is loaded an event is thrown and the listener imageLoadedListener is called

With this I could e.g. design an animated book (using the storyboard API for the scenes) and while one scene is displayed and the user interacts with the scene I already could download the sprite sheets for the next scene (in the createScene event of the next scene I could check if images are already loaded, if not they will be loaded in createScene).

This would give us lots of possibilities to create more user friendly games & books.

Best,
Andreas

[import]uid: 107675 topic_id: 24071 reply_id: 324071[/import]

Depends. Even in Cococa some image loading calls are not thread safe. And best yet, OpenGL Image textures would be a nightmare to put into as OGL talks directly with the hardware. There are always tradeoffs. Easy of use vs complex threading/signaling/locking/etc…

Best bet, is to use proxy images when transitioning to a new scene.
C. [import]uid: 24 topic_id: 24071 reply_id: 97186[/import]

You’re absolutely right, it really would be a challenge.

But if it is only reduced to e.g. one loading task at a time. If you e.g. want to load more than one sprite sheet you have to wait till the first completeEvent is thrown and then you have to start the loading of the next sprite sheet?

And of course the programmer is responsible for NOT using the reference to the sprite sheet as long as it is not loaded? So no complex locking mechanism must be implemented?

Well, reading my own words I guess this would be a feature for advanced coders.
But it just would be great to have it, the opportunities we would have with this…

But of course we will stick with Corona - last week we (a German company) were contacted by B&N, they want our next two apps in development for the Nook devices for the US market - and this would be a pain in the … if we would have coded the apps in ObjectiveC. :slight_smile:

Best,
Andreas
[import]uid: 107675 topic_id: 24071 reply_id: 97898[/import]