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:
Open Xcode and create a new subgroup in the
Resources
group, next to theHunter
and theBackgrounds
groups. Call this new groupBirds
.Open the
Chapter_04/Assets/Birds
folder and drag all images into the newBirds
group in Xcode. Make sure that copy option is checked.Create a new Objective-C class in the
GameObjects
group. Name this classBird
and make it a subclass ofCCSprite
.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
Open the
Bird.m
file and add the following implementation of theinitWithBirdType:
method listed:-(instancetype)initWithBirdType:(BirdType)typeOfBird { //1 ...