Game Development Reference
In-Depth Information
// :/ It's ok, defaults save our day
} finally {
try {
if (in != null )
in.close();
} catch (IOException e) {
}
}
}
There is nothing in this section that we need to go over, really; we've done this before. We try to
read the two Booleans from the file on the SD card. If that fails, we fall back to the default values.
public static void save(FileIO files) {
BufferedWriter out = null ;
try {
out = new BufferedWriter( new OutputStreamWriter(
files.writeFile( file )));
out.write(Boolean. toString ( soundEnabled ));
out.write("\n");
out.write(Boolean. toString ( touchEnabled ));
} catch (IOException e) {
} finally {
try {
if (out != null )
out.close();
} catch (IOException e) {
}
}
}
}
Saving is again very boring. We just store whatever we have, and if that fails, we ignore the error.
This is another good place for improvement, as you'll probably want to let the user know that
something went wrong.
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 we need to remember is to set the
orientation to landscape in the activity's definition in the manifest file. Listing 12-3 shows
the code.
Listing 12-3. AndroidInvaders.java, the Main Activity
package com.badlogic.androidgames.androidinvaders;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
 
Search WWH ::




Custom Search