Spritefont
From BluWiki
Contents |
[edit] Spritefonts
by Benjamin Hale
Part of a series of XNA Tutorials.
To begin using spritefonts, one must add a spritefont reference to the project.
- Right-click the "Content" in the solution explorer.
- Add...
- New Item...
- Select the "Visual C#" category
- Choose "Sprite Font" and give it a name.
This creates an XML file delineating a font.
Example spritefont file without documentation:
<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">
<FontName>Arial</FontName>
<Size>14</Size>
<Spacing>0</Spacing>
<UseKerning>true</UseKerning>
<Style>Regular</Style>
<CharacterRegions>
<CharacterRegion>
<Start> </Start>
<End>~</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
[edit] Properties
- FontName: The name of the font one wishes to use.
- Size: The size one wishes, in points.
- Spacing: Spacing between letters, in pixels.
- UseKerning: Kerning or no?
- Style: Bold, italic, regular.
- CharacterRegions
- CharacterRegion: Which range of characters one wishes to use; inclusive.
- Start: Beginning character; HTML character entity.
- End: Ending character; HTML character entity.
- CharacterRegion: Which range of characters one wishes to use; inclusive.
[edit] Notes
One can use scaling while drawing strings to simulate different-size fonts, but this detracts from quality; going from a smaller size to a larger makes the string blocky, and going from a larger size to a smaller produces resolutio artifacts.
[edit] References
Microsoft, MSDN Library, January 2009






