Azmyth.XNA.PlaneManager.Draw C# (CSharp) Method

Draw() public method

Draws the loaded chunks visible in the viewport
public Draw ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void
        public void Draw(GameTime gameTime)
        {
            if (m_world != null)
            {
                System.Drawing.RectangleF viewportRect = ScreenToTile(new Rectangle(Viewport.X, Viewport.Y, Viewport.Width, Viewport.Height));

                List<TerrainChunk> chunks = m_world.GetChunks(viewportRect);

                m_spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateTranslation(0, 0, 0));

                foreach (TerrainChunk chunk in chunks)
                {
                    List<TerrainTile> tiles = chunk.GetTiles(viewportRect);

                    foreach (TerrainTile t in tiles)
                    {
                        m_spriteBatch.Draw(m_cellTextures[t.Terrain], TileToScreen(t.Bounds), Color.White);

                        #if DEBUG
                            DrawBorder(TileToScreen(t.Bounds), 1, Color.Black);
                        #endif
                    }

                    #if DEBUG
                        Rectangle rect = TileToScreen(chunk.Bounds);
                        string chunkString = "Chunk: (" + (chunk.Bounds.X / m_chunkSize) + "," + (chunk.Bounds.Y / m_chunkSize) + ")";

                        DrawBorder(rect, 1, Color.Red);

                        m_spriteBatch.DrawString(m_spriteFont, chunkString, new Vector2(rect.X + 5, rect.Y), Color.Red);
                    #endif
                }

                m_spriteBatch.End();
            }
        }