Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

12.9. The Main Activity

As usual we have a main activity that derives from the GLGame class. It is responsible for loading the assets through a call to Assets.load() on startup as well as pausing and resuming the music when the activity is paused or resumed. As the start screen we just return the MainMenuScreen, which we will implement shortly. One thing to remember is the definition of the activity in the manifest file. Make sure you have the orientation set to landscape! Listing 12-3 shows you the code.

Example 12-3. DroidInvaders.java, the Main Activity

package com.badlogic.androidgames.droidinvaders;

import javax.microedition.khronos.egl.EGLConfig;

import  javax.microedition.khronos.opengles.GL10;

import  com.badlogic.androidgames.framework.Screen;
import  com.badlogic.androidgames.framework.impl.GLGame;

public class  DroidInvaders extends  GLGame {
    boolean  firstTimeCreate = true ;

    @Override
    public  Screen getStartScreen() {
        return new  MainMenuScreen(this );
    }

    @Override
    public void  onSurfaceCreated(GL10 gl, EGLConfig config) {
        super .onSurfaceCreated(gl, config);
        if  (firstTimeCreate) {
            Settings.load (getFileIO());
            Assets.load (this );
            firstTimeCreate = false ;
        } else  {
            Assets.reload ();
        }
    }

    @Override
    public void  onPause() {
        super .onPause();
        if  (Settings.soundEnabled )
            Assets.music .pause();
    }
}

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial