Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Cocos2d Game Development Blueprints
  • Table Of Contents Toc
Cocos2d Game Development Blueprints

Cocos2d Game Development Blueprints

By : Jorge Jordán
5 (2)
close
close
Cocos2d Game Development Blueprints

Cocos2d Game Development Blueprints

5 (2)
By: Jorge Jordán

Overview of this book

Whether you are a passionate gamer, like developing, or are just curious about game development, this book is for you. The book has been written to teach 2D game development to app developers and to teach Objective-C to game developers, as learning Cocos2d is the perfect step for both roles.
Table of Contents (10 chapters)
close
close
9
Index

Developing a pathfinding algorithm


One way to provide nodes with intelligence is to predefine their behavior in response to external stimuli, or to give them a goal to reach.

In this case, we are going to make our enemies follow a path, which we will subdivide into steps. For this purpose, let's create a new class by following these steps:

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

  2. Click on iOS | cocos2d v3.x | CCNode class and make this class a subclass of CCNode.

  3. Call it PathStep and click on Create.

Replace the contents of PathStep.h with the following lines:

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

@interface PathStep : CCNode {
    
}

// Property for the next step
@property (nonatomic, assign) PathStep *nextPathStep;
// Property for the sprite
@property (readwrite, nonatomic) CCSprite *pathStepSprite;

// Init method
- (PathStep *) initWithPosition:(CGPoint)position;

@end

We are extending the class from CCNode because we need it to...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Cocos2d Game Development Blueprints
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon