Game Development Reference
In-Depth Information
public class MrNom extends AndroidGame {
public Screen getStartScreen() {
return new MainMenu( this );
}
}
We hope you can see why it is beneficial to design a workable framework before diving headfirst
into programming the actual game. We can reuse this framework for all future games that are not
too graphically intensive. Now, let's discuss Listing 5-16, which shows the AndroidGame class,
split up by commentary.
Listing 5-16. AndroidGame.java; Tying Everything Together
package com.badlogic.androidgames.framework.impl;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Window;
import android.view.WindowManager;
import com.badlogic.androidgames.framework.Audio;
import com.badlogic.androidgames.framework.FileIO;
import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.framework.Input;
import com.badlogic.androidgames.framework.Screen;
public abstract class AndroidGame extends Activity implements Game {
AndroidFastRenderView renderView;
Graphics graphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
WakeLock wakeLock;
The class definition starts by letting AndroidGame extend the Activity class and implement the
Game interface. Next, we define a couple of members that should already be familiar. The first
member is AndroidFastRenderView , to which we'll draw, and which will manage our main loop
thread for us. Of course, we set the Graphics , Audio , Input , and FileIO members to instances of
AndroidGraphics , AndroidAudio , AndroidInput , and AndroidFileIO . The next member holds the
currently active Screen . Finally, there's a member that holds a WakeLock that we use to keep the
screen from dimming.
Search WWH ::




Custom Search