Time for action – using states for the bird's life cycle

We're going to give our hunter several tries to hit the bird. This means that the bird will fly on the screen, then fly away, and then return. This sequence will repeat several times. This means we won't be able to use the flipX property to understand whether our bird is flying away completely or just making another pass.

Instead of using the flipX property as a flag, we're going to introduce a state's enum and change the bird's state during the bird's life cycle. Then, when we'll apply some action to the bird. We're going to check whether the bird is in the correct state for this action. Perform the following steps:

  1. Open the Bird.h file and make the following changes to add the new BirdState ...

Get Learning iPhone Game Development with Cocos2D 3.0 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.