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 – adding birds


In this game, the hunter will hunt birds, so let's create a bird object by performing the following steps:

  1. Open Xcode and create a new subgroup in the Resources group, next to the Hunter and the Backgrounds groups. Call this new group Birds.

  2. Open the Chapter_04/Assets/Birds folder and drag all images into the new Birds group in Xcode. Make sure that copy option is checked.

  3. Create a new Objective-C class in the GameObjects group. Name this class Bird and make it a subclass of CCSprite.

  4. Open the Bird.h file and replace its contents with the following code:

    #import "CCSprite.h"
    
    typedef enum BirdType
    {
        BirdTypeBig,
        BirdTypeMedium,
        BirdTypeSmall
    } BirdType;
    
    
    @interface Bird : CCSprite
    
    
    @property (nonatomic, assign) BirdType birdType;
    
    -(instancetype)initWithBirdType:(BirdType)typeOfBird;
    
    @end
  5. Open the Bird.m file and add the following implementation of the initWithBirdType: method listed:

    -(instancetype)initWithBirdType:(BirdType)typeOfBird
    {
        //1
    ...