manlyMiniGames.Map.Draw C# (CSharp) Method

Draw() public method

public Draw ( SpriteBatch batch ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch
return void
        public void Draw(SpriteBatch batch)
        {
            Vector2 topLeft = new Vector2(0.0f, 0.0f);
            Vector2 bottomRight = new Vector2(Globals.screenWidth, Globals.screenHeight);
            Vector2 topLeftTile, bottomRightTile;
            int x, y;

            // Obtain the top left and bottom right tiles according to our world coordinates
            topLeftTile = screenToWorld(topLeft);
            bottomRightTile = screenToWorld(bottomRight);

            //Loop through the tiles that we know to be on the screen.
            for (y = (int)topLeftTile.Y; y <= (int)bottomRightTile.Y; y++)
            {
                for (x = (int)topLeftTile.X; x <= (int)bottomRightTile.X; x++)
                {
                    //get the id of the tile at the current position
                    UInt16 id = Grid(x, y);

                    //Render the correct texture at the current position
                    drawOnMap(batch, tiles[id], new Vector2((float)x, (float)y));
                }
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            map.Draw(spriteBatch);
            player.Draw(spriteBatch, map);
            spriteBatch.End();
            base.Draw(gameTime);
        }