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 side-scroller

The A* algorithm is a generic node-graph traversal routine which can be applied to many abstract problems. In a 2D side-scroller, space is traversed in a complex, non-linear fashion. Actors are expected to run across platforms and jump from platform to platform. With some extra math, we can tailor our A* technique to this problem.

A* pathfinding in a side-scroller

Getting ready

The code listed as follows is heavily edited for the sake of brevity. Please refer to the project RecipeCollection03 for full working code of this recipe.

How to do it...

Execute the following code:

/* SSAStarNode */ @implementation SSAStarNode -(float) costToNeighbor:(SSNeighborNode*)nn ...

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