Reputation: 577
I'm creating a 2d game and i'm using a class with static Texture elements for accessing them from everywhere.Now i want to load my assets asynchronously because i want to show a progress bar with a loading screen.How can i perform this?
Upvotes: 0
Views: 1144
Reputation: 71
Take a look at AsyncTask.
In fact, Google published an article almost exactly what you are trying to do: loading an image in background and display a progress bar while the image is being loaded. The different is, while your code will load stuffs from app resource, the code in google article loads images from network. However, it should point you to the right direction.
See the article at https://sites.google.com/site/androidhowto/how-to-1/create-a-custom-progress-bar-using-asynctask
Note that the code in that article doesn't handle screen rotation well. The problem is, by default, when the screen is rotated, the original is destroyed and the new one is created. If your AsyncTask keeps the any reference to the original one (for example, the one that point to the progress bar object), then it becomes dangling. However, since your app is a game I assume its orientation is fixed, so you might not have to worry about it.
Upvotes: 1