The Main Activity

We need an Activity as the main entry point of our game. We'll call it SuperJumper. Listing 9-3 shows its code.

Listing 9-3., the Main Entry Point Class package com.badlogic.androidgames.jumper;

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 SuperJumper 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.Ioad(getFileIO()); Assets.load(this); firstTimeCreate = false; } else {


^Override public void onPause() { super.onPause(); if(Settings.soundEnabled);

We derive from GLGame and implement the getStartScreen() method, which returns a MainMenuScreen instance. The other two methods are a little less obvious.

We override onSurfaceCreate(), which is called each time the OpenGL ES context is recreated (compare with the code of GLGame in Chapter 6). If the method is called for the first time we use the Assets.load() method to load all assets for the first time, and also load the settings from the settings file on the SD card, if available. Otherwise all we need to do is reload the textures and start playback of the music via the Assets.reload() method. We also override the onPause() method to pause the music in the case it is playing.

We do both of these things so that we don't have to repeat them in the resume() and pause() methods of our screens.

Before we dive into the screen implementations, let's have a look at our new Font class.

0 0

Post a comment