Game Development Reference
In-Depth Information
All that's left is to put our game code into the com.badlogic.androidgames.mrnom package of the
Eclipse project!
MrNomGame: The Main Activity
Our application needs a main entry point, also known as the default Activity on Android.
We will call this default Activity MrNomGame and let it derive from AndroidGame , the class we
implemented in Chapter 5 to run our game. It will be responsible for creating and running our
first screen later on. Listing 6-1 shows our MrNomGame class.
Listing 6-1. MrNomGame.java; Our Main Activity/Game Hybrid
package com.badlogic.androidgames.mrnom;
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.framework.impl.AndroidGame;
public class MrNomGame extends AndroidGame {
public Screen getStartScreen() {
return new LoadingScreen( this );
}
}
All we need to do is derive from AndroidGame and implement the getStartScreen() method,
which will return an instance of the LoadingScreen class (which we'll implement in a minute).
Remember, this will get us started with all the things we need for our game, from setting up the
different modules for audio, graphics, input, and file I/O to starting the main loop thread. Pretty
easy, huh?
Assets: A Convenient Asset Store
The loading screen will load all the assets of our game. But where do we store them? To store
them, we'll do something that is not seen very often in Java land: we'll create a class that has
a ton of public static members that hold all the Pixmap s and Sound s that we've loaded from the
assets. Listing 6-2 shows that class.
Listing 6-2. Assets.java; Holding All of Our Pixmaps and Sounds for Easy Access
package com.badlogic.androidgames.mrnom;
import com.badlogic.androidgames.framework.Pixmap;
import com.badlogic.androidgames.framework.Sound;
public class Assets {
public static Pixmap background ;
public static Pixmap logo ;
 
Search WWH ::




Custom Search