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:
Open the
Bird.h
file and make the following changes to add the newBirdState enum
, newbirdState
property, and aturnaround
method declaration:#import "CCSprite.h" typedef enum BirdType { BirdTypeBig, BirdTypeMedium, BirdTypeSmall } BirdType; typedef enum BirdState { BirdStateFlyingIn, BirdStateFlyingOut...