Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

Layers


Until now, the drawing sequence for the GameObjects is the order in which they are added to the GameEngine. This is inconvenient to say the least. We should improve it.

As most other drawing systems do, our engine should use layers.

Whenever we add a GameObject to the GameEngine, we will pass an integer to indicate the layer we want it to be added to. We will consider 0 to be the layer to add the background to. Think of layers as a z-index for the game objects.

We are going to use four layers. From the foreground to the background, we will display:

  • The Player object: The spaceship

  • Asteroids

  • Bullets

  • The background

To add layer support, we need to modify the GameEngine, StandardGameView, and SurfaceGameView classes. For convenience, we will also update GameObject to know its layer.

On the top level, we will handle the layers as a list of lists of game objects. This is the data structure that we will store in the GameEngine and pass to the implementations of GameView. We will keep the old mGameObject...