claude.lebrun Posted September 26, 2017 Share Posted September 26, 2017 Hi 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], [11,11,11,11,11], [11,11,11,11,11], [11,11,11,11,11], [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++){ myGrid[i].push(m[i*j]); console.log(myGrid[i][j]); } } easystar.setGrid(myGrid); easystar.setAcceptableTiles([11]); /* 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); } } }); easystar.calculate(); }; Link to comment Share on other sites More sharing options...
m4rk2s Posted September 27, 2017 Share Posted September 27, 2017 The same question was asked before here Link to comment Share on other sites More sharing options...
claude.lebrun Posted September 27, 2017 Author Share Posted September 27, 2017 fixed thank you Link to comment Share on other sites More sharing options...
Recommended Posts