[]LayaAir 寻路库,寻路路径错误
已解决:
http://yyztom.com/search/astar 也是基于 Brian Grinstead的js版本写的as3版本,相当快速
http://www.briangrinstead.com/ ... dated
拿走不谢 (附件)
--------------------------------------------------------------------var arr:Array = [[0,1,1],[0,1,1],[0,0,0]];
var opt:Object = {allowDiagonal: true, dontCrossCorners: false, heuristic: Heuristic["manhattan"], weight: 1};
var astart1:AStarFinder = new AStarFinder(opt);
var grid:Grid = new Grid(arr, 3);
var path:Array = astart1.findPath(0, 0, 2, 2, grid);
trace(grid.nodes[0][0].walkable, grid.nodes[1][0].walkable, grid.nodes[2][0].walkable);
trace(grid.nodes[0][1].walkable, grid.nodes[1][1].walkable, grid.nodes[2][1].walkable);
trace(grid.nodes[0][2].walkable, grid.nodes[1][2].walkable, grid.nodes[2][2].walkable);
trace(path.toString());
-------------------------------------输出-----------------------------
true true true 0 0 0
false false true --> 1 1 0
false false true 1 1 0
路径:0,0, 0,1, 1,2, 2,2
然后 0,1, 1,2 的walkable都是false的 (怀疑结果路径的点xy是反的,应该是0,0, 1,0, 2,1, 2,2)
----------------------------------------------------------------------
public function Grid(width_or_matrix:*, height:int, matrix:Array = null)
虽然as3不支持多个构造函数,但是也没必要用这种解决方法吧,包括Grid构造函数初始化的代码简直绕晕了
http://yyztom.com/search/astar 也是基于 Brian Grinstead的js版本写的as3版本,相当快速
http://www.briangrinstead.com/ ... dated
拿走不谢 (附件)
--------------------------------------------------------------------var arr:Array = [[0,1,1],[0,1,1],[0,0,0]];
var opt:Object = {allowDiagonal: true, dontCrossCorners: false, heuristic: Heuristic["manhattan"], weight: 1};
var astart1:AStarFinder = new AStarFinder(opt);
var grid:Grid = new Grid(arr, 3);
var path:Array = astart1.findPath(0, 0, 2, 2, grid);
trace(grid.nodes[0][0].walkable, grid.nodes[1][0].walkable, grid.nodes[2][0].walkable);
trace(grid.nodes[0][1].walkable, grid.nodes[1][1].walkable, grid.nodes[2][1].walkable);
trace(grid.nodes[0][2].walkable, grid.nodes[1][2].walkable, grid.nodes[2][2].walkable);
trace(path.toString());
-------------------------------------输出-----------------------------
true true true 0 0 0
false false true --> 1 1 0
false false true 1 1 0
路径:0,0, 0,1, 1,2, 2,2
然后 0,1, 1,2 的walkable都是false的 (怀疑结果路径的点xy是反的,应该是0,0, 1,0, 2,1, 2,2)
----------------------------------------------------------------------
public function Grid(width_or_matrix:*, height:int, matrix:Array = null)
虽然as3不支持多个构造函数,但是也没必要用这种解决方法吧,包括Grid构造函数初始化的代码简直绕晕了
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
leeq3000
赞同来自:
var arr:Array = [[0,1,1,1],[0,1,1,1], [0,0,0,0]];
Grid的nodes是这样初始化的
0 0 0
1 1 0
1 1 0
1 1 0比如var path:Array = astart1.findPath(0, 0, 3, 2, grid);
对应矩阵就是搜索 nodes[0][0] 到 nodes[2][3]的路径
这两个是反的
Laya_XS
赞同来自: