Closed tootoll closed 6 years ago
Strange how you find your own mistakes as soon as you post question.
I messed up declaring new instance of map every time in code and removing that line after 1 day of searching because of my stupidity realized that it works perfectly
private List<GridCell> pathToEnd;
private AStarGridFinder<GridCell> finder;
private GridFinderOptions opt;
private NavigationGrid<GridCell> navGrid;
@Override
public void show() {
GridCell[][] cells = new GridCell[mapHeight][mapWidth];
for (int x = 0 ; x < mapHeight; x++){
for (int y = 0 ; y < mapWidth; y++){
if (((TiledMapTileLayer) map.getLayers().get(0)).getCell(y, x).getTile().getProperties().get("Blocked") == null){
cells[x][y] = new GridCell(x, y, true);
}else {
cells[x][y] = new GridCell(x, y, false);
}
}
}
opt = new GridFinderOptions();
opt.allowDiagonal = false;
finder = new AStarGridFinder(GridCell.class, opt);
navGrid = new NavigationGrid(cells);
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
pathToEnd = finder.findPath(playerClass.getPositionX()/32, playerClass.getPositionY()/32, (int) coords.y/32, (int) coords.x/32,navGrid);
you have my thanks, work perfectly in every way on android studio.
Hi, im creating GridCell on touchDown() as
Problem with it is that i cant reuse GridCell[][] cells, so i am creating new GridCell[][] cells every time on new search. So am i missing something or is there way to fill GridCell[][] cells on show() and the use old data every time new search is needed on touchDown()?