SpriteBatch.DrawString Method (SpriteFont, String, Vector2, Color, Single, Vector2, Vector2, SpriteEffects, Single)

Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

Syntax

'Declaration
Public Sub DrawString ( _
         spriteFont As SpriteFont, _
         text As String, _
         position As Vector2, _
         color As Color, _
         rotation As Single, _
         origin As Vector2, _
         scale As Vector2, _
         effects As SpriteEffects, _
         layerDepth As Single _
)
public void DrawString (
         SpriteFont spriteFont,
         string text,
         Vector2 position,
         Color color,
         float rotation,
         Vector2 origin,
         Vector2 scale,
         SpriteEffects effects,
         float layerDepth
)
public:
void DrawString(
         SpriteFont spriteFont,
         String text,
         Vector2 position,
         Color color,
         float rotation,
         Vector2 origin,
         Vector2 scale,
         SpriteEffects effects,
         float layerDepth
)

Parameters

  • spriteFont
    Type: SpriteFont
    A font for diplaying text.
  • text
    Type: String
    A text string.
  • position
    Type: Vector2
    The location (in screen coordinates) to draw the sprite.
  • 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

One or more of the following is true:

  • spriteFont is null
  • text is null
InvalidOperationException DrawString was called, but Begin has not yet been called. Begin must be called successfully before you can call DrawString.

Remarks

SpriteFont objects are loaded from the Content Manager. See the SpriteFont class for more information.

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

Use a newline character (\n) to draw more than one line of text.

Requirements

Namespace: Microsoft.Xna.Framework.Graphics

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

See Also

Reference

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

Platforms

Windows Phone