Git Product home page Git Product logo

asyncpathingfinding's Introduction

Async. Path Finding 1.0.0

PhaserJS Path Finding plugin, with optional use of web worker configuration. Fast and Easy to use.

| Quick sample |

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });

function preload() {

}

function create() {
 var asyncPath = game.plugins.add(Phaser.Plugin.asyncPath);
 var PointA = {x: 13, y: 14}; // works fine with Sprite, Point, or any object with x and y properties
 PointB = {x: 22, y: 44};
 Block = {
      Origin: PointA,
      Destination: PointB,
      found: function(path){
              console.log(path);
        },
      notfound: function(){
              console.log('No path found');
        }
    }
  asyncPath.getPath(Block);

}

####Plugin Initialization

asyncPath = game.plugins.add(Phaser.Plugin.asyncPath);

####Block Configuration

Block = {
  Origin: {x:{number}, y:{number}},
  Destination: {x:{number}, y:{number}},
  keepTrack: {boolean}, Optional
  trackBy: {string}, Optional
  Diagonals: {boolean},  Optional
  debugpath: {boolean},  Optional
  Algorithm: {string},  Optional
  forcemain: {boolean},  Optional
  found: {Function}, Optional
  notfound: {Function}  Optional
  }

Origin: {x:{number}, y:{number}}
Destination: {x:{number}, y:{number}}

keepTrack: {boolean} 

The offset is Calculated on tracked blocks and property. If tracked property is greater than or less than offset then new path is calculated from Origin to detination

trackBy: {string} 'Origin' OR 'Destination'

Forces path Manager to set new Diagonal setting for this block

Diagonals: {boolean}

Set the debugging for this block

debugpath: {boolean} 

Set the Algorithm for this block

Algorithm: {string} 'Manhattan' OR 'Euclidean'

Forces this block to be solved on the main UI thread even if there is a web worker

forcemain: {boolean} 

found function is fired each time a path is found

found: {Function} 

notfound function is fired each time a path is not found

notfound: {Function} 

##Plugin Configurations

Setting the plugin with a map

map = game.add.tilemap('mapJSON');
asyncPath.tileMap = map;

Setting up Default watchers offset values in X and Y directions that would trigger a pathfinding calculation on tracked blocks

asyncPath.xyOffset = {number}

X offset trigger

asyncPath.xOffset = {number}

Y offset trigger

asyncPath.xOffset = {number}

Setting up the returned path configuration default pixel

asyncPath.xOffset = {string} 'units' OR 'pixel'

Setting up the algorithm to use in pathFinding

asyncPath.algorithm = {string} 'Manhattan' OR 'Euclidean'

Setting up the return path configuration (if the return path should point to the center of each tile or the edges) default true

asyncPath.centerPaths = {boolean} true OR false 

Setting up the number of paths to be solved on each Phaser frame

asyncPath.pathsPerFrame = {numeber} 

Would debug each block except turned off on a block

asyncPath.defaultdebug = {boolean} true OR false 

Setting custom Cost for vertical and Horizontal movement Default set to 10

asyncPath.VertHorCost = {number} 

Setting Diagonal movement Default set to false

asyncPath.useDiagonal = {boolean} true OR false 

Setting Non walkable tiles

asyncPath.nonWalkableTile = {number} OR {[number]}

Setting Path Debuging color

asyncPath.debugColor = {HEX_NUMBER}

Setting non walkable layer

asyncPath.nonWalkableLayer = {string}

#Creating a web worker for faster path calculations A good choice will be using a web Worker only if you have too many path finding calculations to be done instantly, else setting timers for number of calculations to be done in each Phaser Display frame would be much more efficient. The newWorker() method returns a new webworker instance. Webworkers are managed internally by the plugin;

Note

If there are no web workers, all path finding calculations run on the main UI thread. The returned webworker instance is managed internally by the plugin

asyncPath.newWorker();

Sets Algorithm for webworker

asyncPath.webWorkerAlgorithm = {string} 'Manhattan' OR 'Euclidean'

Set the use of Diagonals in webWorker

asyncPath.webWorkerDiagonals = {boolean} true OR false 

Set the cost of Vertical and Horizontal movement in webWorker

asyncPath.webWorkerVerHorCost = {number}

Set the cost of Diagonal movement in webWorker

asyncPath.webWorkerDiagonalsCost = {number}

asyncpathingfinding's People

Contributors

2p4b avatar

Watchers

Matthias Philipp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.