mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 11:33:28 +00:00
bdea565586
These eliminate the need for the preventRecalc method from v2. If an individual tile is changed with putTileAt, only the min number of faces will be recalculated (vs all faces being recalculated in v2)
32 lines
1 KiB
JavaScript
32 lines
1 KiB
JavaScript
var GetTileAt = require('./GetTileAt');
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
var CalculateFacesWithin = function (tileX, tileY, width, height, layer)
|
|
{
|
|
var above = null;
|
|
var below = null;
|
|
var left = null;
|
|
var right = null;
|
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, layer);
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
{
|
|
var tile = tiles[i];
|
|
|
|
if (tile && 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;
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = CalculateFacesWithin;
|