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

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.