SpriteBatch.Draw Method (Texture2D, Vector2, Nullable<Rectangle>, Color, Single, Vector2, Vector2, SpriteEffects, Single)
Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects and layer.
Syntax
'Declaration
Public Sub Draw ( _
texture As Texture2D, _
position As Vector2, _
sourceRectangle As Nullable(Of Rectangle), _
color As Color, _
rotation As Single, _
origin As Vector2, _
scale As Vector2, _
effects As SpriteEffects, _
layerDepth As Single _
)
public void Draw (
Texture2D texture,
Vector2 position,
Nullable<Rectangle> sourceRectangle,
Color color,
float rotation,
Vector2 origin,
Vector2 scale,
SpriteEffects effects,
float layerDepth
)
public:
void Draw(
Texture2D texture,
Vector2 position,
Nullable<Rectangle> sourceRectangle,
Color color,
float rotation,
Vector2 origin,
Vector2 scale,
SpriteEffects effects,
float layerDepth
)
Parameters
- texture
Type: Texture2D
A texture. - position
Type: Vector2
The location (in screen coordinates) to draw the sprite. - sourceRectangle
Type: Nullable<Rectangle>
A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture. - color
Type: Color
The color to tint a sprite. Use Color.White for full color with no tinting. - rotation
Type: Single
Specifies the angle (in radians) to rotate the sprite about its center. - origin
Type: Vector2
The sprite origin; the default is (0,0) which represents the upper-left corner. - scale
Type: Vector2
Scale factor. - effects
Type: SpriteEffects
Effects to apply. - layerDepth
Type: Single
The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.
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 you can call Draw. |
Remarks
Before making any calls to Draw, you must call Begin. Once all calls to Draw are complete, call End.
If you are texture wrapping with a Reach profile or texture wrapping on Windows Phone, the texture must have power of 2 dimensions.
Requirements
Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)
See Also
Tasks
Concepts
Reference
SpriteBatch Class
SpriteBatch Members
Microsoft.Xna.Framework.Graphics Namespace
Platforms
Windows Phone