开发者

Preloading all images when app starts

开发者 https://www.devze.com 2023-02-16 16:50 出处:网络
I\'m attempting to make a simple game of Pairs for Android. Program Structure Menu.java (Menu activity initially loaded)

I'm attempting to make a simple game of Pairs for Android.

Program Structure

Menu.java (Menu activity initially loaded)

Game.java (Game activity, started by Menu)

GameThread.java (Handles gameloop, calls render process in GameView)

GameView.java (Handles all drawing to the screen)

Graphics.java (Stores loaded images)

The Problem

The problem is that loading all the bitmaps I require for the Game activity takes up to 2 seconds, as there are many images required to animate a set of 15 cards. In order to avoid a large loading time between the Menu and Game activities I was thinking of preloading all of the bitmaps required into the Graphics class, in a new thread when the app first starts (Menu activity), and showing some sort of loading animation.

Then as I can't pass the Graphics store from the Menu activity to the Game activity I would need to make it a static object in the Menu a开发者_开发百科ctivity in order to access it from the Game activity (using Menu.graphics...). Is this a terrible way of doing it? I always thought using static objects was a bad idea? What other options do I have?

Thanks for your help in advance.


I would recommend you use the AsncTask for this. There is also nice into article called Painless Threading on the main Android doc site.

0

精彩评论

暂无评论...
验证码 换一张
取 消