Chapter 9. The Game Engine, Threads, and The Game Loop

During this chapter we will see the game engine come together. By the end of the chapter, we will have an exciting blank screen that draws debugging text at 60 frames per second on a real device, although, probably less on an emulator. While doing so we will learn about programming threads, try-catch blocks, the Runnable interface, Android Activity lifecycle and the concept of a game loop.

My expression of excitement for a blank screen might seem sarcastic but, once this chapter is done we will be able to code and add game objects, almost at will. We will see how much we have achieved in this chapter when we add the moving ball and controllable bat in the next. Furthermore, this game engine code will be used as an approximate template (we will improve it each project) for future projects making the realization of future games faster and easier.

In this chapter, we will be:

  • Coding the PongGame class
  • Coding the draw method and a few more besides
  • Learning about threads and try-catch blocks
  • Implementing the game loop

Let's get started.