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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.