mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
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:
parent
ef942fb204
commit
01f34e18b7
3 changed files with 33 additions and 9 deletions
|
@ -286,6 +286,21 @@ var Tile = new Class({
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -25,17 +25,24 @@ var CalculateFacesWithin = function (tileX, tileY, width, height, layer)
|
|||
{
|
||||
var tile = tiles[i];
|
||||
|
||||
if (tile && tile.collides)
|
||||
if (tile)
|
||||
{
|
||||
above = GetTileAt(tile.x, tile.y - 1, true, layer);
|
||||
below = GetTileAt(tile.x, tile.y + 1, true, layer);
|
||||
left = GetTileAt(tile.x - 1, tile.y, true, layer);
|
||||
right = GetTileAt(tile.x + 1, tile.y, true, layer);
|
||||
if (tile.collides)
|
||||
{
|
||||
above = GetTileAt(tile.x, tile.y - 1, true, layer);
|
||||
below = GetTileAt(tile.x, tile.y + 1, true, layer);
|
||||
left = GetTileAt(tile.x - 1, tile.y, true, layer);
|
||||
right = GetTileAt(tile.x + 1, tile.y, true, layer);
|
||||
|
||||
tile.faceTop = (above && above.collides) ? false : true;
|
||||
tile.faceBottom = (below && below.collides) ? false : true;
|
||||
tile.faceLeft = (left && left.collides) ? false : true;
|
||||
tile.faceRight = (right && right.collides) ? false : true;
|
||||
tile.faceTop = (above && above.collides) ? false : true;
|
||||
tile.faceBottom = (below && below.collides) ? false : true;
|
||||
tile.faceLeft = (left && left.collides) ? false : true;
|
||||
tile.faceRight = (right && right.collides) ? false : true;
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.resetFaces();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -52,6 +52,8 @@ var RecalculateFacesAt = function (tileX, tileY, layer)
|
|||
right.faceLeft = !tileCollides;
|
||||
}
|
||||
|
||||
if (tile && !tile.collides) { tile.resetFaces(); }
|
||||
|
||||
return tile;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue