O'Reilly logo

Learning iPhone Game Development with Cocos2D 3.0 by Kirill Muzykov

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

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

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