gamvas.AStarMap

Description

A flexible 3D node based A* pathfinding system

For a simpler to use 2D grid based system, have a look at gamvas.AStarGrid

Constructor

new gamvas.AStarMap(withFirst);

Parameters

withFirstinclude the first element of a path when searching (optional, default: true) Example:

Create a new path finding system and add two nodes that are connected to each other.

var pathFind = new gamvas.AStarMap();
// create nodes
var n1 = new AStarNode(10, 2);
var n2 = new AStarNode(100, 50);
// set connection between nodes
n1.connect(n2);
// add the nodes to the system
pathFind.add(n1);
pathFind.add(n2);
// find the path between two points in space
var path = pathFind.find(5, 1, 120, 40);
Summary
gamvas.AStarMapA flexible 3D node based A* pathfinding system
Functions
addAdd a gamvas.AStarNode to the node system
findFind a path between two points in 2D space, or two gamvas.AStarNode elements

Functions

add

add: function(n)

Add a gamvas.AStarNode to the node system

Note

Keep in mind, that by just adding it, it is not connected to anything.  See gamvas.AStarNode.connect

find

find: function(nxs,
nys,
xe,
ye)

Find a path between two points in 2D space, or two gamvas.AStarNode elements

Parameters

This function has two alternative ways to use it

A) by specifying points in 2D space

map.find(x1, y1, x2, y2);

B) by specifying nodes

map.find(node1, node2);

Example

var pathFind = new gamvas.AStarMap();
// create nodes
var n1 = new AStarNode(10, 2);
var n2 = new AStarNode(100, 50);
var n3 = new AStarNode(250, 25);
// set connection between nodes
n1.connect(n2);
n2.connect(n3);
// add the nodes to the system
pathFind.add(n1);
pathFind.add(n2);
pathFind.add(n3);
// find the path using the nodes instead of using 3d coordinates
var path = pathFind.find(n1, n3);
add: function(n)
Add a gamvas.AStarNode to the node system
A base class for pathfinding nodes.
find: function(nxs,
nys,
xe,
ye)
Find a path between two points in 2D space, or two gamvas.AStarNode elements
A class to simplify A* pathfinding on a 2x2 grid with a optional height field
connect: function(n,
auto)
Connect two nodes
Close