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

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