It is the cleanest and the simplest method I have seen, but might not be conventional. It works though, no black screen is seen while loading game.
1. Inside onLoadResources I loaded only splash texture.
2. Inside onLoadScene I created only splash scene and returned it.
3. Then I created methods loadResources() and loadScenes() and I added all stuff that needs to be loaded for the game inside those two methods.
4. Then in the onLoadComplete I used TimerHandler with minimum delay, after which I called methods from 3. and the first game scene to be shown, in my case it is mMenuScene. TimerHandler is the crucial thing for this to work, without TimerHandler it shows black screen instead of splash. Since I'm not an expert, I cannot explain exactly why this works, maybe some of you can. I hope it will be of use.
Using java Syntax Highlighting
- public class MainGameActivity extends BaseGameActivity {
- // ===========================================================
- // Final Fields
- // ===========================================================
- // ===========================================================
- // Constants
- // ===========================================================
- private static final int CAMERA_WIDTH = 480;
- private static final int CAMERA_HEIGHT = 800;
- // ===========================================================
- // Fields
- // ===========================================================
- protected Camera mCamera;
- // splash scene
- protected Scene mSplashScene;
- private BitmapTextureAtlas mSplashBackgroundTextureAtlas;
- private TextureRegion mSplashBackgroundTextureRegion;
- // menu scene
- protected Scene mMenuScene;
- // ...
- // ===========================================================
- // Methods for/from SuperClass/Interfaces
- // ===========================================================
- @Override
- public Engine onLoadEngine() {
- this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
- return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera).setNeedsSound(true));
- }
- @Override
- public void onLoadResources() {
- BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
- mSplashBackgroundTextureAtlas = new BitmapTextureAtlas(512, 1024, TextureOptions.NEAREST);
- mSplashBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mSplashBackgroundTextureAtlas, this, "splash.jpg", 0, 0);
- mEngine.getTextureManager().loadTextures(mSplashBackgroundTextureAtlas);
- }
- @Override
- public Scene onLoadScene() {
- mSplashScene = new Scene();
- mSplashScene.setBackgroundEnabled(false);
- mSplashScene.attachChild(new Sprite(0, 0, mSplashBackgroundTextureRegion));
- return this.mSplashScene;
- }
- @Override
- public void onLoadComplete() {
- mEngine.registerUpdateHandler(new TimerHandler(0.01f, new ITimerCallback() {
- @Override
- public void onTimePassed(final TimerHandler pTimerHandler) {
- mEngine.unregisterUpdateHandler(pTimerHandler);
- loadResources();
- loadScenes();
- mEngine.setScene(mMenuScene);
- }
- }));
- }
- // ===========================================================
- // Methods
- // ===========================================================
- public void loadResources() {
- // menu resources
- // help resources
- // pick level resources
- // game resources
- }
- public void loadScenes() {
- // menu scene
- // help scene
- // pick level scene
- // game scene
- }
- }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
Edit: I added other parts of activity, so it will be clearer what I'm writing about.

