The documentation on msdn only produces errors.
The demo has 5 errors and won't run (it lacks a ton of things like
proper references and the entire content) and documentation on the
SpriteFont class is lacking crucial information and the example
produces errors as well.
Apparently at least one
<CharacterRegion> with and
<Start> and <End> is needed, but what values do they need
if I have no unicode characters and just want to display simple text?
I copied the example XML from the msdn documentation and substituted "Courier New" with "Comic Sans":
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
|
| 3 |
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> |
| 4 |
<Asset Type="Graphics:FontDescription"> |
| 5 |
<FontName>Comic Sans</FontName> |
| 6 |
<Size>18</Size> |
| 7 |
<Spacing>0</Spacing> |
| 8 |
<UseKerning>true</UseKerning> |
| 9 |
<Style>Regular</Style> |
| 10 |
<CharacterRegions> |
| 11 |
<CharacterRegion> |
| 12 |
<Start>32</Start> |
| 13 |
<End>127</End> |
| 14 |
</CharacterRegion> |
| 15 |
</CharacterRegions> |
| 16 |
</Asset> |
| 17 |
</XnaContent> |
This gets me the following error for lines 12 and 13 (start and end):
There was an error while deserializing intermediate XML. String must be exactly one character long.
If I change <Start> to 1 and <End> to 9, I get the following error:
Unsupported type. Cannot find a ContentTypeWriter
implementation for
Microsoft.Xna.Framework.Content.Pipeline.Graphics.FontDescription.
The code I use for displaying it in the Draw method:
| 1 |
string text = "Error"; |
| 2 |
SpriteFont sf = Content.Load<SpriteFont>("Font"); //Content\Font.xml |
| 3 |
Vector2 origin = sf.MeasureString(text); |
| 4 |
foreground.DrawString(sf, text, pos, Color.Black, |
| 5 |
0, origin, 1.0f, SpriteEffects.None, 0.5f); |
Really, all I want is do display some text, why is it so difficult?
I'd really appreciate if someone could tell me a way that really works.
Thanks.