A* pathfinding on a grid
A classic video game problem is that of pathfinding. Intelligent actors are often required to navigate around obstacles during gameplay. The A* search algorithm (also known as A Star) is commonly used to solve pathfinding by efficiently traversing a constructed node graph. In this recipe, we will demonstrate grid-based A* pathfinding.
Getting ready
Please refer to the project RecipeCollection03 for full working code of this recipe.
How to do it...
Execute the following code:
/* AStarNode */ @interface AStarNode : NSObject { CGPoint position; //The node's position on our map NSMutableArray *neighbors; //An array of neighbor AStarNode ...
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.