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 ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.