Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – animating the shooting and limiting the shooting rate


We will continue to add states to the game objects, and this time, we will update the Hunter class. We're going to animate the process of reloading the arrow and will limit the shooting rate. Let's do this using the following steps:

  1. Open the Hunter.h file and add HunterState enum right after the last #import directive:

    typedef enum HunterState
    {
        HunterStateIdle,
        HunterStateAiming,
        HunterStateReloading
    } HunterState;
  2. Then, add a property called hunterState to the Hunter class as follows:

    @property (nonatomic, assign) HunterState hunterState;
  3. Add a declaration of the method called getReadyToShootAgain using the following line of code:

    -(void)getReadyToShootAgain;
  4. Switch to the Hunter.m file and import the CCAnimation.h header as follows:

    #import "CCAnimation.h"
  5. Then, initialize the hunter state to the HunterStateIdle state inside the if block in the init method as follows:

    self.hunterState = HunterStateIdle;
  6. Scroll down...