Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Extending CCSprite


Dr. Nicholas Fringe's enemies are an army of UFOs controlled by very intelligent extraterrestrial beings trying to wipe out all of mankind. That's why we're going to create them as a separate class that will derive from CCSprite, where we will define its evolved behavior.

Some developers prefer to derive this kind of class from CCNode and include a CCSprite instance as it offers more potential, but for the moment we are going to keep it simple and just extend CCSprite.

First of all, let's create the new class:

  1. Right-click on the Classes group in the project navigator and select New File….

  2. Click on iOS | cocos2d v3.x and choose to create the new file from the CCNode class template.

  3. Type CCSprite in the available field and click on Next.

  4. Call the file as UFO and be sure that the Classes folder is selected before clicking on Create.

Then replace the contents of UFO.h with the following block of code:

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface UFO : CCSprite...