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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.