public void DrawLayer(SpriteBatch spriteBatch, Layer layer, Camera gameCamera, Vector2 offset, float alpha, Color color)
{
if (!layer.Visible)
return;
TileLayer tileLayer = layer as TileLayer;
if (tileLayer != null)
{
Rectangle worldArea = new Rectangle((int)gameCamera.Position.X - (gameCamera.Width+200), (int)gameCamera.Position.Y - (int)(gameCamera.Height*1.5), (gameCamera.Width *2)+400, gameCamera.Height*3);
// figure out the min and max tile indices to draw
int minX = Math.Max((int)Math.Floor((float)worldArea.Left / TileWidth), 0);
int maxX = Math.Min((int)Math.Ceiling((float)worldArea.Right / TileWidth), Width);
int minY = Math.Max((int)Math.Floor((float)worldArea.Top / TileHeight), 0);
int maxY = Math.Min((int)Math.Ceiling((float)worldArea.Bottom / TileHeight), Height);
for (int x = minX; x < maxX; x++)
{
for (int y = minY; y < maxY; y++)
{
//if ((new Vector2((x * TileWidth) + (TileWidth/2), (y * TileHeight) + (TileHeight/2)) - new Vector2(worldArea.Center.X, worldArea.Center.Y)).Length() < gameCamera.Width * 3f)
//{
Tile tile = tileLayer.Tiles[x, y];
if (tile == null)
continue;
// - tile.Source.Height + TileHeight;
Rectangle r = new Rectangle(x * TileWidth, y * TileHeight, tile.Source.Width, tile.Source.Height);
spriteBatch.Draw(tile.Texture, r, tile.Source, color);
//}
}
}
}
}