mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Removed repetative code.
This commit is contained in:
parent
00a38f744a
commit
ad24a0b8ec
1 changed files with 18 additions and 39 deletions
|
@ -26,66 +26,45 @@ var CullTiles = function (layer, camera, outputArray)
|
|||
if (outputArray === undefined) { outputArray = []; }
|
||||
|
||||
outputArray.length = 0;
|
||||
|
||||
|
||||
var y = 0;
|
||||
var x = 0;
|
||||
var tile = null;
|
||||
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
|
||||
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
|
||||
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
|
||||
var mapData = layer.data;
|
||||
var mapWidth = layer.width;
|
||||
var mapHeight = layer.height;
|
||||
|
||||
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
|
||||
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
|
||||
|
||||
// Camera world view bounds, snapped for tile size
|
||||
|
||||
var boundsLeft = SnapFloor(camera.worldView.x, tileW) - (tilemapLayer.cullPaddingX * tileW);
|
||||
var boundsRight = SnapCeil(camera.worldView.right, tileW) + (tilemapLayer.cullPaddingX * tileW);
|
||||
var boundsTop = SnapFloor(camera.worldView.y, tileH) - (tilemapLayer.cullPaddingY * tileH);
|
||||
var boundsBottom = SnapCeil(camera.worldView.bottom, tileH) + (tilemapLayer.cullPaddingY * tileH);
|
||||
|
||||
var skipCull = tilemapLayer.skipCull;
|
||||
var drawLeft = skipCull ? 0 : Math.max(0, boundsLeft / layer.tileWidth);
|
||||
var drawRight = skipCull ? mapWidth : Math.min(mapWidth, boundsRight / layer.tileWidth);
|
||||
var drawTop = skipCull ? 0 : Math.max(0, boundsTop / layer.tileHeight);
|
||||
var drawBottom = skipCull ? mapHeight : Math.min(mapHeight, boundsBottom / layer.tileHeight);
|
||||
|
||||
// If skipping cull, loop through every tile in the map.
|
||||
|
||||
if(tilemapLayer.skipCull)
|
||||
for (y = drawTop; y < drawBottom; y++)
|
||||
{
|
||||
for (y = 0; y < mapHeight; y++)
|
||||
for (x = drawLeft; x < drawRight; x++)
|
||||
{
|
||||
for (x = 0; x < mapWidth; x++)
|
||||
tile = mapData[y][x];
|
||||
|
||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
outputArray.push(tile);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var drawLeft = Math.max(0, boundsLeft / layer.tileWidth);
|
||||
var drawRight = Math.min(mapWidth, boundsRight / layer.tileWidth);
|
||||
var drawTop = Math.max(0, boundsTop / layer.tileHeight);
|
||||
var drawBottom = Math.min(mapHeight, boundsBottom / layer.tileHeight);
|
||||
|
||||
for (y = drawTop; y < drawBottom; y++)
|
||||
{
|
||||
for (x = drawLeft; x < drawRight; x++)
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
outputArray.push(tile);
|
||||
}
|
||||
outputArray.push(tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue