Bricklayer.Common.World.Tile.Draw C# (CSharp) Method

Draw() public method

Handles drawing of a single tile
public Draw ( SpriteBatch spriteBatch, Microsoft.Xna.Framework.Graphics.Texture2D texture, Vector2 drawPosition, int x, int y, int z, bool flat = false ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch
texture Microsoft.Xna.Framework.Graphics.Texture2D
drawPosition Vector2
x int
y int
z int
flat bool
return void
        public virtual void Draw(SpriteBatch spriteBatch, Texture2D texture, Vector2 drawPosition, int x, int y, int z, bool flat = false)
        {
            if (block.ID == BlockType.Empty.ID)
                return; //If empty, nope.exe out of here

            //Foreground blocks
            if (z == 1)
            {
                drawPosition.X = (x * Tile.Width);
                drawPosition.Y = ((y * Tile.Height) - (Tile.DrawHeight - Tile.Height)) + 1;
                Rectangle source = Block.Source;

                if (flat) //The flat flag is for only drawing the 2D face of the block, and not the top + right 3D edges
                {
                    if (Block.Collision != BlockCollision.Impassable)
                        return; //Don't draw non solid blocks above the player

                    source.Y += 4;
                    source.Width = Tile.Width;
                    source.Height = Tile.Height;
                    drawPosition.Y += 4;
                }
                spriteBatch.Draw(texture, drawPosition, source, Color.White);
            }
            //Background blocks
            else if (z == 0)
            {
                if (Block.Layer == Layer.Background) //Draw background normally
                {
                    drawPosition.X = (x * Tile.Width);
                    drawPosition.Y = ((y * Tile.Height) - (Tile.DrawHeight - Tile.Height)) + 1;
                    spriteBatch.Draw(texture, drawPosition, Block.Source, Color.White);
                }
                else if (Block.Layer == Layer.All) //If block has foreground and background versions, calculate the background source
                {
                    Rectangle source = Block.Source;
                    source.Y += 4;
                    source.Width = Tile.Width;
                    source.Height = Tile.Height;
                    drawPosition.X = (x * Tile.Width) + 4;
                    drawPosition.Y = ((y * Tile.Height) - (Tile.DrawHeight - Tile.Height)) + 1;
                    spriteBatch.Draw(texture, drawPosition, source, backgroundTint);
                }
            }
        }