Microsoft.Xna.Framework.Graphics.SpriteBatch.Draw C# (CSharp) Method

Draw() public method

Submit a sprite for drawing in the current batch.
public Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector2 position, Rectangle sourceRectangle, System.Color color, float rotation, System.Vector2 origin, System.Vector2 scale, SpriteEffects effects, float layerDepth ) : void
texture Microsoft.Xna.Framework.Graphics.Texture2D A texture.
position System.Vector2 The drawing location on screen.
sourceRectangle Rectangle An optional region on the texture which will be rendered. If null - draws full texture.
color System.Color A color mask.
rotation float A rotation of this sprite.
origin System.Vector2 Center of the rotation. 0,0 by default.
scale System.Vector2 A scaling of this sprite.
effects SpriteEffects Modificators for drawing. Can be combined.
layerDepth float A depth of the layer of this sprite.
return void
		public void Draw (Texture2D texture,
				Vector2 position,
				Rectangle? sourceRectangle,
				Color color,
				float rotation,
				Vector2 origin,
				Vector2 scale,
				SpriteEffects effects,
                float layerDepth)
		{
            CheckValid(texture);

            var w = texture.Width * scale.X;
            var h = texture.Height * scale.Y;
			if (sourceRectangle.HasValue)
            {
				w = sourceRectangle.Value.Width*scale.X;
				h = sourceRectangle.Value.Height*scale.Y;
			}

            DrawInternal(texture,
				new Vector4(position.X, position.Y, w, h),
				sourceRectangle,
				color,
				rotation,
				origin * scale,
				effects,
                layerDepth,
				true);
		}

Same methods

SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle destinationRectangle, System.Color color ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, System.Color color ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, System.Color color, float rotation, System.Vector2 origin, SpriteEffects effects, float layerDepth ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector2 position, System.Color color ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector2 position, Rectangle sourceRectangle, System.Color color ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector2 position, Rectangle sourceRectangle, System.Color color, float rotation, System.Vector2 origin, float scale, SpriteEffects effects, float layerDepth ) : void
SpriteBatch::Draw ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector2 position = null, Rectangle destinationRectangle = null, Rectangle sourceRectangle = null, System.Vector2 origin = null, float rotation = 0f, System.Vector2 scale = null, System.Color color = null, SpriteEffects effects = SpriteEffects.None, float layerDepth = 0f ) : void

Usage Example

Example #1
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
        {
            sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, _rasterizerScissorsState);

            sb.Draw(frameText, new Rectangle(X, Y, width, height), Color.White);

            //if (new Rectangle(X, Y, width, height).Contains((int)GUI.InputManager.MousePosition.X, (int)GUI.InputManager.MousePosition.Y))
            //    if(GUI.InputManager.MouseManager.State.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            //        sb.Draw(backText, ClientArea, Color.Gray);
            //    else
            //        sb.Draw(backText, ClientArea, Color.LightGray);
            //else

            sb.Draw(backText, ClientArea, topColor);
            topColor = Color.White;

            Rectangle oldsc = sb.GraphicsDevice.ScissorRectangle;

            sb.GraphicsDevice.ScissorRectangle = ClientArea;

            sb.DrawString(Parent.Font, drawText, new Vector2(ClientArea.X + 3, ClientArea.Y + 3 - text_y_scroll), Color.Black); //, 0, Vector2.Zero, 1f, SpriteEffects.None, 0);
            //sb.DrawString(font, drawString, new Vector2(destination.X, destination.Y - yoffset), color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0);

            sb.GraphicsDevice.ScissorRectangle = oldsc;

            sb.End();
        }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.SpriteBatch::Draw