O'Reilly logo

Building iOS 5 Games: Develop and Design by James Sugrue

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

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 ...

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