Fixed a path following problem in AISprite.action_wander

This commit is contained in:
2014-07-06 21:30:18 -07:00
parent 5aaa025537
commit 870c00d537
2 changed files with 16 additions and 26 deletions

View File

@@ -633,28 +633,8 @@
"x":0, "x":0,
"y":0 "y":0
}, },
{
"x":0,
"y":32
},
{
"x":64,
"y":96
},
{
"x":288,
"y":96
},
{ {
"x":352, "x":352,
"y":32
},
{
"x":352,
"y":0
},
{
"x":0,
"y":0 "y":0
}], }],
"properties": "properties":

View File

@@ -606,20 +606,30 @@ var AISprite = function(game, x, y, key, frame) {
return; return;
} }
if ( isSet(this.sprite_route) == true ) { if ( isSet(this.sprite_route) == true ) {
if ( this.path.length > 0 && this.path_index >= this.path.length ) { if ( this.path.length > 0 &&
this.path_index >= this.path.length &&
isSet(this.target) &&
this.x == this.target.x &&
this.y == this.target.y ) {
this.sprite_route_index += 1; this.sprite_route_index += 1;
if ( this.sprite_route_index >= this.sprite_route.polyline.length )
this.sprite_route_index = 0;
this.path_purge(); this.path_purge();
} }
if ( this.sprite_route_index >= this.sprite_route.polyline.length )
this.sprite_route_index = 0;
var dpoint = this.sprite_route.polyline[this.sprite_route_index]; var dpoint = this.sprite_route.polyline[this.sprite_route_index];
if ( isSet(this.target) == false ) { if ( isSet(this.target) == false ) {
this.target = new Phaser.Sprite(null, this.target = new Phaser.Sprite(null,
this.sprite_route.x + dpoint[0], this.sprite_route.x + dpoint[0],
this.sprite_route.y + dpoint[1]); this.sprite_route.y + dpoint[1]);
} else { } else {
this.target.x = this.sprite_route.x + dpoint[0]; if ( isSet(this.target.sprite_group) == true ) {
this.target.y = this.sprite_route.y + dpoint[1]; this.target = new Phaser.Sprite(null,
this.sprite_route.x + dpoint[0],
this.sprite_route.y + dpoint[1]);
} else {
this.target.x = this.sprite_route.x + dpoint[0];
this.target.y = this.sprite_route.y + dpoint[1];
}
} }
this.chasetarget(this.target, this.chasetarget(this.target,
STATE_NONE, STATE_NONE,