Jump to content

Getting a 2D array for Easystar?


fallenshadow
 Share

Recommended Posts

Hi all,

I have been trying to follow this tutorial here:

https://developer.tizen.org/community/tip-tech/using-easystar.js-implement-pathfinding-tizen-game-projects

However, it mentions about a 2D array and right away I'm lost. I have a game in Phaser Isometric but I don't use a 2D array at all. I just have a tile and a loop to add to a tile group.

spawnTiles: function () {
        var tile;
        for (var xx = 0; xx < 400; xx += 38) {
            for (var yy = 0; yy < 400; yy += 38) {
                // Create a tile using the new game.add.isoSprite factory method at the specified position.
                // The last parameter is the group you want to add it to (just like game.add.sprite)
                tile = game.add.isoSprite(xx, yy, 0, 'tile', 0, tileGroup);
                tile.anchor.set(0.5, 0);
            }
        }
    }

How do I get a 2D array for Easystar to use?

Link to comment
Share on other sites

You could do something like:

var tile;
var map = [];
var tileWidth = 38;
for (var xx = 0; xx < 10; xx++) {
  map[xx] = [];
  for (var yy = 0; yy < 10; yy++) {
    // Create a tile using the new game.add.isoSprite factory method at the specified position.
    // The last parameter is the group you want to add it to (just like game.add.sprite)
    tile = game.add.isoSprite(xx  tileWidth, yy * tileWidth, 0, 'tile', 0, tileGroup);
    tile.anchor.set(0.5, 0);
    map[xx][yy] = 1;
  }
}

console.log(map)

But you should probably look into tilemaps and Tiled, it'll help a lot.

Also, there's a Phaser plugin to help out with pathfinding: https://github.com/appsbu-de/phaser_plugin_pathfinding

 

Link to comment
Share on other sites

  • 5 weeks later...

So I thought I was making progress now but I'm hitting an issue when I try this:

Quote

Easystar - Your start or end point is outside the scope of your grid.

function movePlayer() {
    
    easystar.findPath(player.isoX, player.isoY, selectedTile.isoX, selectedTile.isoY, drawPath);
    easystar.calculate();
}

Any ideas?

Link to comment
Share on other sites

  • 9 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...