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