As our zombie is going to perform several movements such as walk, run, or hit and it will have some attributes as the life points, we will create a class for it. Follow these steps:
Right-click on the Classes group in the project navigator and select New File….
Click on iOS | cocos2d v3.x | CCNode class.
Make this class a subclass of
CCNode
, call itZombie
, and click on Create.
Replace the contents of Zombie.h
with:
#import <Foundation/Foundation.h> #import "cocos2d.h" #import "CCAnimation.h" typedef enum { stateStill = 0, stateWalking, stateRunning, stateHitting } ZombieStates; @interface Zombie : CCNode { } @property (readwrite, nonatomic) int lifePoints; @property (readwrite, nonatomic) ZombieStates *state; @property (readwrite, nonatomic) CCSprite *zombieSprite; @property (readonly, nonatomic) CCActionAnimate *actionStill; @property (readonly, nonatomic) CCActionRepeatForever *actionWalk; @property (readonly, nonatomic) CCActionRepeatForever...