TiledLib.Map.DrawLayer C# (CSharp) Method

DrawLayer() public method

Draws a single layer of the map
public DrawLayer ( SpriteBatch spriteBatch, TiledLib.Layer layer, Camera gameCamera, Vector2 offset, float alpha, Color color ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch The SpriteBatch to use to render the layer.
layer TiledLib.Layer
gameCamera Camera The camera to use for positioning.
offset Vector2 A pixel amount to offset the tile positioning by
alpha float Layer opacity.
color Color The color to use when drawing.
return void
        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);
                        //}

                    }
                }

            }
        }

Same methods

Map::DrawLayer ( SpriteBatch spriteBatch, string layerName, Camera gameCamera ) : void
Map::DrawLayer ( SpriteBatch spriteBatch, string layerName, Camera gameCamera, Color color ) : void
Map::DrawLayer ( SpriteBatch spriteBatch, string layerName, Camera gameCamera, Vector2 shadowOffset, float alpha ) : void