in-game loading bar

Ok so, in this game we made, you create your own characters.
You have several options to choose between body, eyes, mouths, etc…
Each character has it’s own spritesheet with all his features in it.
Each time you press the BODY button, the current character spritesheet is removed and a new one is loaded.
This takes some time, between 500ms-1000ms depending in the spritesheet’s size.
While this is happening, game obviously freezes.
It’s normal, cause it is loading data, but people who have tried the game believe it actually freezes as a bug, and tap several times on the same BODY button so there’s a huge amount of spritesheets to be loaded and unloaded.
I decided to implement 2 solutions to this. First one, body button is not touchable again until spritesheet finished loading.
Second, i want a “loading” circle animation or “wait” text or something to appear on screen while this happens, but haven’t achieved on doing it. Obviously while the game loads the spritesheet, everything else freezes. Is there any way to have this kind “loading” or “wait” animation WHILE the spritesheet is been loaded??

Hope i made myself clear :stuck_out_tongue:
Thanks!
[import]uid: 105206 topic_id: 22177 reply_id: 322177[/import]

Activity indicator would be a good option here - take a look at CoronaSDK > SampleCode > Interface > NativeDisplayObjects.

Peach :slight_smile: [import]uid: 52491 topic_id: 22177 reply_id: 88279[/import]

ok, great peach, will look at it.
thanks! [import]uid: 105206 topic_id: 22177 reply_id: 88327[/import]

No worries; I think you’ll like it - it will prevent the user tapping to load the next body again, too :slight_smile: [import]uid: 52491 topic_id: 22177 reply_id: 88410[/import]

You were right, i like it! haha
Now, i still have some trouble with it.
For what i read, i can’t set it true and false anywhere in order to make it work, but i don’t seem to find the right spot.

I have a “selection” function which calls changeBody function.
so i set the activity indicator to true just before calling changeBody.
Where should i place the false?? inside change Body? inside selection? another function?
I tried all these but can’t make it work :S

local function selection()
blah blah blah
if…
blah blah blah
native.setActivityIndicator(true)
changeBody()
end
blah blah, etc…
end

thanks peach! [import]uid: 105206 topic_id: 22177 reply_id: 88477[/import]

I haven’t played with this a lot but I’m thinking perhaps inside the change body function after the code where you load the next image - can you try that and tell me results?

I plan on playing with this more this week, I think it’s an awesome feature, so I’m sure we can figure out how best to use it with your project :slight_smile: [import]uid: 52491 topic_id: 22177 reply_id: 88582[/import]

@Peach Can this be used for Android devices too? [import]uid: 38820 topic_id: 22177 reply_id: 88601[/import]

No, it’s iOS only. Sorry! [import]uid: 52491 topic_id: 22177 reply_id: 88612[/import]

Since you said it takes generally 500ms-100ms you could try something like this…

local function selection()  
 blah blah blah  
 if...  
 blah blah blah  
 native.setActivityIndicator( true )  
 changeBody()  
  
 local closeIndicator = function() return native.setActivityIndicator( false ) end  
 timer.performWithDelay(1200, closeIndicator, 1)  
 end  
end  

This would first turn on the activity indicator and call your change body, then after 1200ms (you can change this number to however long you think your maximum wait time is on loading) it will close the indicator. [import]uid: 69700 topic_id: 22177 reply_id: 88618[/import]

>This would first turn on the activity indicator and call your change body, then after 1200ms (you can change this number to however long you think your maximum wait time is on loading) it will close the indicator.

My understanding is that the whole system completely freezes until the sprite sheet is loaded, so you wouldn’t even need the timer. Just something like:
[lua]local function selection()
blah blah blah
if…
do
blah blah blah
native.setActivityIndicator( true )
changeBody()
end
native.setActivityIndicator( false )
end
end[/lua]

I stuck the disable outside of the code block with the changeBody() function, but I don’t know if that would even be necessary, it would have to be tested. At any rate, the idea is that as soon as the sheet is loaded, the system un-freezes and the next thing it sees is a call to disable the activity indicator. I’d prefer this over the timer because hardware changes and you never know if the next generation would be able to load the sheet in half the time. [import]uid: 14598 topic_id: 22177 reply_id: 88626[/import]

@peach, ertzel, alanfalcon

First of all thanks everybody!

Now, the way it actually worked is the one suggested by ertzel.
For some reason it doesn’t work without the timer, even if you declare a specific function to set the indicator to false.
What i ended up doing, was to set a timer of 1ms. I tried it and it worked. Each time i unload/load the spritesheet, it takes only the needed time to do it.

If i do it the other way, by just writing native.setActivityIndicator(false) or within a function and call it in but without timer, it seems like if the indicator is set to true and false before doing the changeBody function. When this happens, it actually never appears on screen.

I should say i only tried this on the simulator, not testing on device yet.

And peach, thanks, this was what i needed, i love you!!
[import]uid: 105206 topic_id: 22177 reply_id: 88702[/import]

Fantastic, thanks for doing the tests and sharing the results! I like your hybrid solution that A) works and B) doesn’t take any longer than it has to. I hope it works well on the device as well! [import]uid: 14598 topic_id: 22177 reply_id: 88718[/import]

Well tested on device.
It respects the time you specified, so 1ms is too short in order for the indicator to appear.
And still doesn’t work if no timer is set.
So timer with specific time is, for now, the answer. [import]uid: 105206 topic_id: 22177 reply_id: 88727[/import]

You also may want to check out my Load Progress bar

http://developer.anscamobile.com/code/load-progress-bar

The latest version of the code can be found here:

http://www.homebrewsoftware.com/Download/CoronaSDK/HomebrewLoadingBar_v1_31.zip [import]uid: 16734 topic_id: 22177 reply_id: 88750[/import]

@KenRogoway,
Cool man, i’ll check it out, thanks! [import]uid: 105206 topic_id: 22177 reply_id: 88872[/import]