Next we will write an xNa program that displays some greetings in the center of the screen. Text is often widely used in Silverlight, and is usually used for text profiling or playing or displaying scores. This is a "Hello, world" that cannot be used as a research or example of a complete xNa program.
In fact, xNa does not have any built-in fonts. You may think that an xNa mobile phone program can use the same local font as Silverlight, but this is not the case. Silverlight uses vector-based TrueType fonts, but xNa does not know these foreign concepts. In xNa, everything is a bitmap, including a font.
If you want to include a specific font in your xNa project, the font must be embedded into an executable file as a collection containing bitmap for each character. XNa game studio (integrated with Visual Studio) can easily embed fonts, but it will lead to some difficult legal issues. Unless the law permits distribution of embedded fonts, most fonts are distributed together with Windows itself or Windows applications, but this is not commercial.
To help you solve this legal confusion, Some fonts authorized by Microsoft are designed to embed you in your xNa solution. Here they are:
Note that the Pericles font is authorized to use lower-case letters, so it may only be suitable for titles.
Select New and project from the Visual Studio file menu. On the left side of the dialog box, select Visual C # And xNa game studio 4.0. In the middle, select Windows Phone game (4.0), select a location, and enter the project name xnahellophone.
Visual Studio creates two projects. One is the program and the other content of the program. XNa programs usually contain a lot of content, mainly bitmap and 3D models, but also suitable for fonts. To add a font to this program, right-click the project content (marked with "xnahellophonecontent (cintent)" and select Add and new item from the pop-up menu. Select sprite font, complete the file name as spritefont1.spritefont, and then click Add.
The word "sprite" is common in game programming. It usually refers to a small bitmap that can be quickly moved, like any genie that may be encountered in the Magic Forest. In xNa, even the font is Sprite.
The spritefont1.spritefont file list is displayed in the content directory. You can edit the description font of the XML file.
XNa project: xnahellophone file: spritefont1.spritefont (complete w/o comments)
Segoe UI mono
14
0
True
~
You will see segoe UI mono In the tag name, but you can change it to another font that is listed above. If you want Pericles light, put the full name there, but if you want Miramonte bold, Pescadero bold, or segoe UI mono bold, use only Miramonte, Pescadero, or segoe UI mono, and enter the bold style between labels. You can use other fonts as bold, but for other fonts, bold will be merged, while Miramonte, Pescadero or segoe UI mono, you will get the real design font.
The size label indicates the point size of the font. XNa in Silverlight, you can almost fully process pixel coordinates and dimensions, but the conversion between point and point between xNa pixels is based on a 96 DPI display. The size of becomes 18-2/3 pixels in your xNa program. This is very close to the "standard" font size of 15point20px in Silverlight windowsphone.
The characterregions section of this file indicates the hexadecimal encoding range of the Unicode characters you need. By default, from 0x32 to 0x126, all non-control characters of the ASCII character set are included.