Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have some problems with figuring out what value I should put in the function:

int value_needed_to_figure_out = X;
ProgressBar.incrementProgressBy(value_needed_to_figure_out);

I've been researching about loading screens and how to use them. Some examples I've seen have implemented Thread.sleep() in a Handler.post(new Runnable()) function. To me, I got most of that concept of using the Handler to update the ProgressBar, while pretending to do some heavy crunching work. So, I kept looking.

I have read this thread here: How do I load chunks of data from an assest manager during a loading screen?

It said that I can try using a stack it needs to load, and adding a size counter as I add elements to the stack. What does it mean? This is the part where I'm totally stumped.

If anyone would provide some hints, I'll gladly appreciate it. Thanks in advance.

share|improve this question
    
I realize it might be a bit overwhelming to look at but try getting some ideas from the libgdx AssetManager which uses a ThreadPool to process assets in the background. code.google.com/p/libgdx/source/browse/trunk/gdx/src/com/… –  Rubber Mallet Mar 31 '12 at 19:19

1 Answer 1

up vote 1 down vote accepted

The answer in the another thread is pretty straight forward. But a step by step guide:

Make a stack of resources
Fill the stack, as you fill it, count the size of each object and put in the fullSize var
in loop, when still have resources in stack, do:
    pop stack top item
    load this resource
    get the loaded resource size and put it on the currentLoaded var
    update progressbar to currentLoaded / fullSize

As you saw, you get the size of all resources together, this will be the fullSize. And keep another variable together to count what have already been loaded, this will be currentLoaded. Just increase currentLoaded with the last resource loaded size, and get the final percentage with currentLoaded / fullSize.

Was this explanation fine for you?

share|improve this answer
    
How do I fill the stack? I tried using AssetManager to obtain the assets, and then got stuck from here. I don't know how you could push individual assets/resource files into the stack one by one. I also tried googling for some examples on filling the stack in android, but nothing good comes up. Link Also, when you push in an asset/resource file into the stack, do you know how to obtain the individual file's size? –  tom_mai78101 Apr 1 '12 at 6:28
    
You could do something simple, like a class that store the file name and its size. then just load the file by its name and account its size. That's all –  Gustavo Maciel Apr 1 '12 at 6:30
    
Nevermind my old comment. I think I can figure the size problem out. The main question is answered, I thank you for your hints. –  tom_mai78101 Apr 1 '12 at 8:23
    
@tom_mai78101 Consider also upvoting it, if it was helpful (: –  Gustavo Maciel Apr 1 '12 at 17:35
    
I need to have 15 reps to upvote. I only have 3. :/ –  tom_mai78101 Apr 1 '12 at 18:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.