FuncWorks.XNA.XTiled.Map.DrawLayer C# (CSharp) Method

DrawLayer() public method

Draws given tile layer
public DrawLayer ( SpriteBatch spriteBatch, Int32 layerID, Rectangle region, System.Single layerDepth ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method
layerID System.Int32 Index of the layer to draw in the Map.TileLayers collection
region Microsoft.Xna.Framework.Rectangle Region of the map in pixels to draw
layerDepth System.Single LayerDepth value to pass to SpriteBatch
return void
        public void DrawLayer(SpriteBatch spriteBatch, Int32 layerID, Rectangle region, Single layerDepth)
        {
            DrawLayer(spriteBatch, layerID, ref region, layerDepth);
        }

Same methods

Map::DrawLayer ( SpriteBatch spriteBatch, Int32 layerID, Rectangle &region, Int32 txMin, Int32 txMax, Int32 tyMin, Int32 tyMax, System.Single layerDepth ) : void

Usage Example

Example #1
0
        private void DrawLayersInOrder(Map map, SpriteBatch spriteBatch, Rectangle viewport)
        {
            float layerDepth = 1.0f;
            float layerDepthDec = 1.0f / (float)map.LayerOrder.Length;

            foreach (var layer in map.LayerOrder)
            {
                switch (layer.LayerType)
                {
                    case LayerType.TileLayer:
                        map.DrawLayer(spriteBatch, layer.ID, viewport, layerDepth);
                        break;

                    case LayerType.ObjectLayer:
                        map.DrawObjectLayer(spriteBatch, layer.ID, viewport, layerDepth);
                        break;

                    case LayerType.ImageLayer:
                        map.DrawImageLayer(spriteBatch, layer.ID, viewport, layerDepth);
                        break;
                }

                layerDepth -= layerDepthDec;
            }
        }