7. Blowing Stuff Up

In Chapter 6, the enemy was introduced, but the player couldn’t shoot or be shot. In this chapter, you’ll load up some collision detection and explosion animation, along with the logic to destroy enemies.

Collision Detection Methods

So what is collision detection? It’s a check to see if two sprites occupy the same space to determine, for example, if a missile has hit a player or enemy sprite. A 2D game such as Raiders uses three main methods of collision detection.

Bounding Box Detection

Bounding box detection checks the bounds of a sprite to see if they cross the bounds of another sprite. A simple diagram paints the picture (Figure 7.1).

Figure 7.1 The left image has no collision, but the right image is a hit!

The red boxes ...

Get Building iOS 5 Games: Develop and Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.