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

Using GameView


Until now, we have been using standard views and translating them to render the different elements of the game. While this is an easy way to draw elements on the screen, it is far from being efficient. We are relying on the system layout to do the drawing.

While this technique is fine for a turn-based game or any non-real-time game in general, it cannot render enough frames per second for a real-time game.

Note

Working with standard Views is fine for non-real-time games.

We are going to create a custom View that we are going to call GameView. This view will be responsible for drawing the sprites.

We already noted the duplication of code and mentioned the concept of sprite in the previous chapter. We will now move forward and create a Sprite class that will take care of drawing an image at specific coordinates inside the GameView.

There are two ways of drawing at low level on Android. They are:

  • Extending View and overriding onDraw

  • Extending SurfaceView and using SurfaceHolder

In both...