πŸ“œ ⬆️ ⬇️

Path search in 2D space: AStar component (action script 3.0)

This article is a description of the AStar component that implements the simplest path search using the A * algorithm. There are many source codes with the implementation of this algorithm, but the component I propose is easy to use and well documented. Despite the small number of methods and properties, the component is very flexible and applicable in many areas (although, of course, game developers will like it most of all). The component will be updated in accordance with the wishes and comments of readers. Therefore, I ask all those interested to write me a mail or in the comments.


The component file can be found here:
1) depositfiles.com/files/ptsxof3p9
2) ifolder.ru/14260428

ESSENCE OF SEARCH
')
For a successful search, the plane along which a certain entity moves and searches for a path must be divided into β€œtiles” (see Figure 1) . I, as a rule, store information about such a field in a two-dimensional array of objects.
image
Figure 1 - A field of "tiles" (shaded tiles are obstacles)

In each object that describes the "tile" (from this point on let's move to the term "node" instead of "tile") in the simplest case its coordinates are stored on the screen and a sign of whether this tile is an obstacle. As a rule, this is a boolean expression, where, if true, this node is an obstacle, and if false, it is a free node. When developing a component, I came up with the term β€œ obstacle map ”; it will be useful in explaining the operation of a component. An obstacle map is a two-dimensional array that stores Boolean expressions that characterize the permeability of each node (whether the node is an obstacle or not). Based on the obstacle map, the component searches for a path.
Now let's create an obstacle map using the simplest example, and then proceed to the study of the component methods. Suppose we want to create a 5 by 7 field and make some cells impassable for this, do the following:

1) Initialize the obstacle map, setting each node to false β€” a node free for passing
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}

, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .
var obstacle_map:Array=[];
for ( var i: int =0; i<5; i++) {
obstacle_map[i]=[];
for ( var j: int =0; j<5; j++) {
obstacle_map[i][j]= false ;
}
}




2) , true.

obstacle_map[0][0]= true ;
obstacle_map[1][1]= true ;
obstacle_map[2][1]= true ;
obstacle_map[2][3]= true ;
obstacle_map[3][3]= true ;
obstacle_map[4][3]= true ;
obstacle_map[0][4]= true ;




, 2 – .

2 –

, , AStar.

–

, , , :
var a_star:AStar= new AStar();


a_star a_star.ERROR:
a_star.addEventListener(a_star.ERROR,onError);


, . onError. , , :

private function onError(e:Event): void {
trace(a_star.lastError);
}



, a_star, lastError. – . 3 output . , , .



3 –

:
a_star.setObstacleMap(obstacle_map);

! AStar.ERROR AStar, . , . setObstacleMap - , lastError . , – , . , , .. , , , , AStar, .

Event.COMPLETE:
a_star.addEventListener(Event.COMPLETE,onComplete);

onComplete , clippingType ( ):

a_star.clippingType=<>

, : a_star.F ( full), a_star.P ( prevent) a_star.N ( none). a_star.N , . ? , . . 4 S (start) , f (finish) .



4 –

clippingType (. 5)



5. – clippingType=a_star.N .
5. – , . clippingType=a_star.P . : , ( , 3D ) , , . , «» , . 6, , – .



6 –

clippingType=a_star.P ( ) , . , , .

5. , – clippingType=a_star.F . .. .
, . , :

AStar.findPath(_startx:int,_starty:int,_targetx:int,_targety:int):void

{0,1} {6, 3}. findPath:
a_star.findPath(0,1,6,3);

, Event.COMPLETE (, ?), a_star . a_star my_path:Array:

private function onComplete(e:Event): void {
my_path=a_star.getPath();
}


, , . { _x: < >, _y: < >}. , 5.:

my_path=[
{_x:0,_y:1},
{_x:1,_y:0},
{_x:1,_y:2},
{_x:1,_y:3},
{_x:2,_y:4},
{_x:3,_y:5},
{_x:3,_y:6}
];


. , .

Source: https://habr.com/ru/post/71083/


All Articles