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

A* pathfinding on a grid

A classic video game problem is that of pathfinding. Intelligent actors are often required to navigate around obstacles during gameplay. The A* search algorithm (also known as A Star) is commonly used to solve pathfinding by efficiently traversing a constructed node graph. In this recipe, we will demonstrate grid-based A* pathfinding.

A* pathfinding on a grid

Getting ready

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

How to do it...

Execute the following code:

/* AStarNode */ @interface AStarNode : NSObject { CGPoint position; //The node's position on our map NSMutableArray *neighbors; //An array of neighbor AStarNode ...

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