2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-22 01:16:46 +00:00
|
|
|
var GetTileAt = require('./GetTileAt');
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Calculates interesting faces at the given tile coordinates of the specified layer. Interesting
|
|
|
|
* faces are used internally for optimizing collisions against tiles. This method is mostly used
|
|
|
|
* internally to optimize recalculating faces when only one tile has been changed.
|
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.CalculateFacesAt
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {integer} tileX - The x coordinate.
|
|
|
|
* @param {integer} tileY - The y coordinate.
|
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2017-11-27 13:33:30 +00:00
|
|
|
*/
|
2018-01-29 22:30:57 +00:00
|
|
|
var CalculateFacesAt = function (tileX, tileY, layer)
|
2017-11-22 01:16:46 +00:00
|
|
|
{
|
|
|
|
var tile = GetTileAt(tileX, tileY, true, layer);
|
|
|
|
var above = GetTileAt(tileX, tileY - 1, true, layer);
|
|
|
|
var below = GetTileAt(tileX, tileY + 1, true, layer);
|
|
|
|
var left = GetTileAt(tileX - 1, tileY, true, layer);
|
|
|
|
var right = GetTileAt(tileX + 1, tileY, true, layer);
|
|
|
|
var tileCollides = tile && tile.collides;
|
|
|
|
|
|
|
|
// Assume the changed tile has all interesting edges
|
|
|
|
if (tileCollides)
|
|
|
|
{
|
|
|
|
tile.faceBottom = true;
|
|
|
|
tile.faceBottom = true;
|
|
|
|
tile.faceLeft = true;
|
|
|
|
tile.faceRight = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset edges that are shared between tile and its neighbors
|
|
|
|
if (above && above.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceTop = false; }
|
|
|
|
above.faceBottom = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (below && below.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceBottom = false; }
|
|
|
|
below.faceTop = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left && left.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceLeft = false; }
|
|
|
|
left.faceRight = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right && right.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceRight = false; }
|
|
|
|
right.faceLeft = !tileCollides;
|
|
|
|
}
|
|
|
|
|
2017-11-30 23:18:27 +00:00
|
|
|
if (tile && !tile.collides) { tile.resetFaces(); }
|
|
|
|
|
2017-11-22 01:16:46 +00:00
|
|
|
return tile;
|
|
|
|
};
|
|
|
|
|
2018-01-29 22:30:57 +00:00
|
|
|
module.exports = CalculateFacesAt;
|