Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text, screen position, color tint, rotation, origin, scale, effects, and depth.

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

public void DrawString (
         SpriteFont spriteFont,
         StringBuilder text,
         Vector2 position,
         Color color,
         float rotation,
         Vector2 origin,
         Vector2 scale,
         SpriteEffects effects,
         float layerDepth


The sprite font.
The mutable (read/write) string to draw.
The location, in screen coordinates, where the text will be drawn.
The desired color of the text.
The angle, in radians, to rotate the text around the origin.
The origin of the string. Specify (0,0) for the upper-left corner.
Vector containing separate scalar multiples for the x- and y-axes of the sprite.
Rotations to apply prior to rendering.
The sorting depth of the sprite, between 0 (front) and 1 (back).

Exception typeCondition
ArgumentException There is a character in text that was not imported by the SpriteFont. You must include all the characters in the character regions in the sprite font file. For more information, see How To: Extend the Font Description Processor to Support Additional Characters.
ArgumentNullException spriteFont or text is null.
InvalidOperationException DrawString was called, but Begin has not yet been called. Begin must be called successfully before DrawString can be called.

By accepting a StringBuilder argument in place of a String argument, this form supports measurement of dynamically formatted text.

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.

Xbox 360, Windows XP SP2, Windows Vista, Zune

Community Additions

© 2015 Microsoft