Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

easystarjs in a phaser game


Recommended Posts


This is a basic project from phaser quest that i have forked https://github.com/claudelebrun/basic-mmo-phaser

i would like to use easystarjs to move the player from a point to another

it finds a path with a basic tilemap but i want to make the player moves and i don't know how

here is the code of the moving function that was a tween before and now it uses easystarjs

Game.movePlayer = function(id,x,y){
  var player = Game.playerMap[id];
  var m = game.cache.getTilemapData('map').data.layers[0].data;
  var grid = [[11,11,11,11,11],
    var myGrid = new Array();
    for(i=0; i<23; i++){
      myGrid[i] = new Array();
      for(j=0; j<16; j++){

  console.log(Math.floor(player.x/32), Math.floor(player.y/32));
  console.log(Math.floor(x/32), Math.floor(y/32));
    easystar.findPath(Math.floor(player.x/32), Math.floor(player.y/32), Math.floor(x/32), Math.floor(y/32), function( path ) {
    	if (path === null) {
    	 console.log("Path was not found.");
    	} else {
    	 console.log("Path was found.");
       var tween = game.add.tween(player);
       var duration = 1000;
       for(i=0; i<path.length;i++){
         console.log(path[i].x + " " + path[i].y);
          tween = game.add.tween(player).to({ x: path[i].x*32, y: path[i].y*32 }, 1000, Phaser.Easing.Linear.None, true);




Link to comment
Share on other sites


  • Recently Browsing   0 members

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