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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.