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 the hunter


It is time to add the hunter back to the game. However, this time the birds will have fun. So, instead of shooting the birds, the hunter will be running around and dodging the stones that they throw at him.

There will be quite a lot of code to add, so here is a brief explanation of what we want to do. We want to create a new class for our hunter, as we cannot reuse the old Hunter class. Our new hunter class, PhysicsHunter, will have two animations: idle and running. We will control the hunter by touching the screen. When we touch the screen on the left-hand side, the hunter will run to the left, and when we touch the right-hand side of the screen, the hunter will run to the right. When we don't touch the screen, the idle animation should be played. Let's start:

  1. Create a new Objective-C class in the GameObjects group. Name the class PhysicsHunter and make it a subclass of CCSprite.

  2. Open the PhysicsHunter.h file and replace its contents with following code...