所以,我正在使用 A* Pathfinding
。我让它工作,但它并没有一直工作。它一直工作到右边的最后 4
列。诡异的。
它一直有效,直到 X 等于或小于 10。这很奇怪,因为 Y
的最大值是 10
。也许是在一起了?我不知道。但我的 map 是 15 列
x 10 行
。这是一个在线示例:http://mystikrpg.com/html5/
试试点击 map 右侧,看看怎么不行?现在尝试单击某处,使 X
为 10 或以下。它应该有效。
我遇到的一个有趣的错误是Uncaught TypeError: Cannot read property '8' of undefined
。
8
是您点击位置的 Y
。如果您单击右侧的第一个灰色 block (因为第 0 行被隔离)。然后 8
会说 1
。
这是它布置节点的部分。
// Creates a Graph class used in the astar search algorithm.
function Graph(grid) {
var nodes = [];
var row, rowLength, len = grid.length;
for (x = 0; x <= 10; x++) {
row = grid[x];
nodes[x] = new Array(15);
for (y = 0; y <= 15; y++) {
nodes[x][y] = new GraphNode(x, y, row[y]);
}
}
this.input = grid;
this.nodes = nodes;
}
最佳答案
您的 loadmap
函数返回一个包含 11 个元素的数组。
例如,当 x_block
为 13 时,graph.nodes[x_block][y_block]
返回 undefined。
关于JavaScript/jQuery - 数组列表没有遍历整个板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10445582/