Share via


SpriteBatch.Draw Method (Texture2D, Rectangle, Nullable<Rectangle>, Color)

Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination and source rectangles, and color tint.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public void Draw (
         Texture2D texture,
         Rectangle destinationRectangle,
         Nullable<Rectangle> sourceRectangle,
         Color color
)

Parameters

  • texture
    The sprite texture.
  • destinationRectangle
    A rectangle specifying, in screen coordinates, where the sprite will be drawn. If this rectangle is not the same size as sourcerectangle the sprite will be scaled to fit.
  • sourceRectangle
    A rectangle specifying, in texels, which section of the rectangle to draw. Use null to draw the entire texture.
  • color
    The color channel modulation to use. Use Color.White for full color with no tinting.

Exceptions

Exception type Condition
ArgumentNullException texture is null.
InvalidOperationException Draw was called, but Begin has not yet been called. Begin must be called successfully before Draw can be called.

Remarks

Before any calls to Draw, you must call Begin. Once all calls to Draw are complete, call End.

See Also

Tasks

How to: Draw a Sprite

Concepts

2D Graphics Overview

Reference

SpriteBatch Class
SpriteBatch Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista