O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Processing AI waypoints

One of the most basic AI processes involves moving an AI actor around in a physical environment. To do this, we will create a queue of waypoints. Each waypoint represents the next position we want our actor to move to.

Processing AI waypoints

Getting ready

Please refer to the project RecipeCollection03 for full working code of this recipe.

How to do it...

Execute the following code:

#import "GameWaypoint.h" @interface GameActor : GameObject { NSMutableArray *waypoints; float runSpeed; } @end @implementation GameActor -(void) processWaypoints { bool removeFirstWaypoint = NO; //The actor's position onscreen CGPoint worldPosition = CGPointMake(self.body->GetPosition().x ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required