Jump to content

Plugin for pathfinding on maps (using easystar.js)


casarock
 Share

Recommended Posts

Hi,

 

I've created a plugin for phaser which adds a wrapper for Easystar.js (https://github.com/prettymuchbryce/easystarjs). 

 

I guess there is room for improvements, but it works! You could find it here: https://github.com/appsbu-de/phaser_plugin_pathfinding. feel free to use and improve it! 

 

Cheers!

 

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
  • 2 months later...

I've set up a test and everything seems to work fine. But I just can't figure out, how to publish the path in the callback to other objects.

The path for example should be attached to the player, as the object will listen if path-information will be available and track along.

I don't want to use asynchronity, as the screen is small enough and if it's not done within 1000 iteration, the move will be void.

 

My tries so far:

[..]findPath: function() {        pathfinder.setCallbackFunction(function(path) {            path = path || [];            this.pathfinder.resultSet = path;            this.pathfinder.isReady = true;        });            this.pathfinder.preparePathCalculation(this.getPlayerTile(), this.getInputTile());            this.pathfinder.calculatePath();            //console.log(this.pathfinder.resultSet);    },update: function () {        if (this.pathfinder.isReady) {            console.log('calculation is ready');            this.player.path = this.pathfinder.resultSet;            this.pathfinder.isReady = false;        }         [..]    }[..]
'use strict';var TempPath = {isReady: false, resultRest: []};[..]function TestPathFinder() { };TestPathFinder.prototype = {[..]findPath: function() {        pathfinder.setCallbackFunction(function(path) {            path = path || [];            TempPath.resultSet = path;            TempPath.isReady = true;        });            this.pathfinder.preparePathCalculation(this.getPlayerTile(), this.getInputTile());            this.pathfinder.calculatePath();    }    update: function () {        if (TempPath.isReady) {            console.log('calculation is ready');            this.player.path = TempPath.resultSet;            TempPath.isReady = false;        }[..]    }};

Everything is set up fine as following callback will give results:

pathfinder.setCallbackFunction(function(path) {            path = path || [];            console.log(path);        });

How can I solve it? I'm finally so near to a practical solution.. :/

Link to comment
Share on other sites

Found the solution:

pathfinder.setCallbackFunction(function(path) {            path = path || [];            TempPath.resultSet = Object.create(path);            TempPath.isReady = true;        });

I needed to clone the result, not just set a reference to it.

Anyway. Is there any planned efforts for a phaser inbuilt path finder? Maybe with a choice of a* or jps?

Link to comment
Share on other sites

  • 7 months later...

After thinking about it for a while I've decided the best course of action would be to dynamically generate a grid A* could interpret which represents where all the sprites are. Squares on the grid would need to be at least the size of the smallest sprite (preferably half the size) and when sprites are moved, the grid would update. I'm pretty sure this is the easiest way to achieve pathfinding with sprites being walkable/non-walkable instead of tiles.

 

My concern is that the grid squares will have to be extremely small, like 5 x 5 and that's a lot of squares on a map that is 3k x 3k... wouldn't generating and dynamically updating such a grid suck up a lot of memory?

 

Does anyone have any comments/suggestions?  

Link to comment
Share on other sites

  • 11 months later...

This post is a bit older but maybe someone is still serious, I use the latest easystar, and everything works fine but:
you can not update your grid. Easystar will output no path if you re-run the "setGrid" function..

Seems like this is common behavior? Any solutions?
If you run a "building" game, or some kind of strategic game, the pathfinding is useless without refreshing the grid.

kind regards
 

Link to comment
Share on other sites

This post is a bit older but maybe someone is still serious, I use the latest easystar, and everything works fine but:

you can not update your grid. Easystar will output no path if you re-run the "setGrid" function..

Seems like this is common behavior? Any solutions?

If you run a "building" game, or some kind of strategic game, the pathfinding is useless without refreshing the grid.

kind regards

 

In my implementation, the grid gets thrown out every time you use it. So you need to use a copy of the grid rather than the grid itself to find a path. I'm pretty sure this is common behavior on most a* implementations.  

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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