Recalculate faces: make this reset faces on non-colliding tiles

This handles edge cases where things like copy can make a tile become non-colliding w/o reseting faces
This commit is contained in:
Michael Hadley 2017-11-30 17:18:27 -06:00
parent ef942fb204
commit 01f34e18b7
3 changed files with 33 additions and 9 deletions

View file

@ -286,6 +286,21 @@ var Tile = new Class({
return this; return this;
}, },
/**
* Reset faces.
*
* @returns {this}
*/
resetFaces: function ()
{
this.faceTop = false;
this.faceBottom = false;
this.faceLeft = false;
this.faceRight = false;
return this;
},
/** /**
* Sets the collision flags for each side of this tile and updates the interesting faces list. * Sets the collision flags for each side of this tile and updates the interesting faces list.
* *

View file

@ -25,7 +25,9 @@ var CalculateFacesWithin = function (tileX, tileY, width, height, layer)
{ {
var tile = tiles[i]; var tile = tiles[i];
if (tile && tile.collides) if (tile)
{
if (tile.collides)
{ {
above = GetTileAt(tile.x, tile.y - 1, true, layer); above = GetTileAt(tile.x, tile.y - 1, true, layer);
below = GetTileAt(tile.x, tile.y + 1, true, layer); below = GetTileAt(tile.x, tile.y + 1, true, layer);
@ -37,6 +39,11 @@ var CalculateFacesWithin = function (tileX, tileY, width, height, layer)
tile.faceLeft = (left && left.collides) ? false : true; tile.faceLeft = (left && left.collides) ? false : true;
tile.faceRight = (right && right.collides) ? false : true; tile.faceRight = (right && right.collides) ? false : true;
} }
else
{
tile.resetFaces();
}
}
} }
}; };

View file

@ -52,6 +52,8 @@ var RecalculateFacesAt = function (tileX, tileY, layer)
right.faceLeft = !tileCollides; right.faceLeft = !tileCollides;
} }
if (tile && !tile.collides) { tile.resetFaces(); }
return tile; return tile;
}; };