How to use "a star algorithm" to find path in cocos2dx?

How to use "a star algorithm" to find path in cocos2dx?
0.0 0


Hi everyone:

I’m developing a RPG game on Windows Phone,I desired to make player touch wherever of the screen then the protagonist of game will Automatically move to that place around obstacles.
So the “a star algorithm” seems proper,I have studied the thinking of this algorithm,but still don’t know how to achieve it?

Hoping some one give me some prompts,or the code,either on C++ or C#.



A* is easy to implement using a tilemap.


tilemap->setWeight( 10, 10, 1.0f );//set the weight of the tile at (10,10)
std::vector path = tilemap->findPath( pointa, pointb );//pathfind

The requirements are that you will need to put a “weight” value on each node in the tilemap so that the A* algorithm knows where to avoid.
An option is to subclass the tilemap class in Cocos2d, adding a pathfind function and storing the weight of each node.


Thank you,but I exactly don’t know how to write the pathfind function,and also,there are obstacles on the map,how to bypass them?