SpriteBatch.DrawString Method (SpriteFont, StringBuilder, Vector2, Color)
Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.
Syntax
'Declaration
Public Sub DrawString ( _
spriteFont As SpriteFont, _
text As StringBuilder, _
position As Vector2, _
color As Color _
)
public void DrawString (
SpriteFont spriteFont,
StringBuilder text,
Vector2 position,
Color color
)
public:
void DrawString(
SpriteFont spriteFont,
StringBuilder text,
Vector2 position,
Color color
)
Parameters
- spriteFont
Type: SpriteFont
A font for diplaying text. - text
Type: StringBuilder
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.
Exceptions
Exception type | Condition |
---|---|
ArgumentNullException | One or more of the following is true:
|
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