O'Reilly logo

Mastering Android Game Development by Raul Portales

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
Layers

To add layer support, we need to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required