A* pathfinding in a Box2D world

The real fun of the A* algorithm comes from applying it to more complex scenarios. In this recipe, we will apply the grid-based technique of the last recipe to a Box2D world filled with randomly generated polygons.

A* pathfinding in a Box2D world

Getting ready

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

How to do it...

Execute the following code:

@interface Ch7_Box2DPathfinding : GameArea2D { NSMutableArray *grid; float nodeSpace; //The space between each node, increase this to increase A* efficiency at the cost of accuracy int gridSizeX; int gridSizeY; } @end @implementation Ch7_Box2DPathfinding -(CCLayer*) runRecipe ...

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.