Game Development Reference
In-Depth Information
Modifying the MainActivity Class
Next, we have to make modifications to our MainActivity class.
The m_GLView needs to be changed to:
private MyGLSurfaceView m_GLView;
The onPause() function has to be modified to save the state of the game when onPause() is called.
(See Listing 6-53.)
Listing 6-53. Modifying the onPause() Function
@Override
protected void onPause()
{
super.onPause();
m_GLView.onPause();
// Save State
m_GLView.CustomGLRenderer.SaveGameState();
}
Finally, run the project, change orientations, and exit and reenter the program repeatedly.You should
now have a score and health that are saved when you exit the program or change orientations. You
should also see that the two cubes' orientation and physics are saved as well.
Summary
In this chapter, I covered the game environment. We started off by creating sounds. Code was
presented that supported the creation and playback of sounds. Next, we went through a hands-on
example in which we added sound effects, applying this code to two colliding cubes. A HUD was
discussed. Then the code required to implement this HUD was discussed, followed by a case study
that implemented the HUD using the code. Finally, a way was presented to save the state of your
game environment. A hands-on example was also presented, which demonstrated how you would
save the state of your HUD as well as the state of objects in your game.
 
Search WWH ::




Custom Search