I’m working with the rex Board setup, and so far it’s working pretty well, I like the setup is pretty easy and I can see how to start tying things into my “board” data object.
However, I can’t quite figure out how to use the pathfinder, it always just returns an empty array or some integer value, seems to usually be 1 was expecting with the occupiedTest and blockedTest set to false that I should always get something. Seems it’s supposed to be a list of {x, y} objects?
No idea what’s missing, sample code:
#drawBoard() {
const SCALE = 0.7;
const board = [
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
];
this.board = this.#scene.rexBoard.add.board({
grid: this.#scene.rexBoard.add.hexagonGrid({
x: 48.5,
y: 200 + 50 * SCALE,
cellWidth: 97 * SCALE,
cellHeight: 100 * SCALE,
hexSideLength: 48.5 * SCALE,
staggeraxis: 'x',
staggerindex: 'odd',
// type: 'flat',
}),
width: 5,
height: 5
});
this.board.forEachTileXY((tile) => {
if (board[tile.y][tile.x] === null) {
return;
}
const sprite = this.#scene.add.sprite(0, 0, 'terrain', board[tile.y][tile.x]).setDepth(0).setScale(SCALE);
this.board.addChess(sprite, tile.x, tile.y, 'terrain');
});
// This works (can see the image on top of the terrain, Yay!).
const sprite = this.#scene.add.sprite(0, 0, 'baddies', board[1][1]).setDepth(1).setScale(0.5);
this.board.addChess(sprite, 1, 1, 'unit');
//
this.board.setInteractive();
this.board.on('tiledown', (pointer) => {
const tile = this.board.worldXYToTileXY(pointer.worldX, pointer.worldY);
if (board[tile.y][tile.x] !== null) {
console.log(tile.x + ':' + tile.y);
}
});
//
const finder = this.#scene.rexBoard.add.pathFinder(this.board, {
occupiedTest: false, // true, false => no difference
blockedTest: false,// true, false => no difference
pathMode: 'A*', // tried 1, 10, 'A*' => no difference
});
// Valid chess
var chess = this.board.tileXYZToChess(1, 1, 'unit');
console.log(chess)
const start = { x: 1, y: 1 };
const end = { x: 4, y: 1 };
console.log(finder.findPath(chess, end)); // returns []
console.log(finder.findPath(chess, end.x, end.y)); // returns []
console.log(finder.findPath(start, end)); // returns []
console.log(finder.findPath(start.x, start.y, end.x, end.y)); // returns 1
}