1

Is there any way to use custom fonts in XNA?

artem
  • 16,382
  • 34
  • 113
  • 189

1 Answers1

4

Sure, you need to import the font to your system. Add the font to the font system catalog or add through control panel. When it is ready (reboot Visual Studio) use the custom template for SpriteFont in Visual studio, which generates an XML file. An exmaple:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">

    <!--
    Modify this string to change the font that will be imported.
    -->
    <FontName>Moire</FontName>
...
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
  • The question is about Windows Phone 7, not PC. – artem Feb 25 '12 at 17:25
  • Conent Pipline will fetch the font. Try it. it should build and run without a problem. – Lukasz Madon Feb 25 '12 at 18:13
  • Error 2 Cannot autodetect which importer to use for "Fonts\PreludeFLF.ttf". There are no importers which handle this file type. Specify the importer that handles this file type in your project. C:\src\c#\wp7-count-game\Numbers\NumbersLibContent\Fonts\PreludeFLF.ttf NumbersLib – artem Feb 25 '12 at 18:55
  • 1
    Are you sure you made it properly? Have a look http://msdn.microsoft.com/en-us/library/bb447673.aspx . You should not use the font directly. Use spritfont to import the font. Alternatively, you can change the font to a bitmap http://create.msdn.com/en-US/education/catalog/utility/bitmap_font_maker – Lukasz Madon Feb 25 '12 at 19:08
  • 2
    Right click the content project name and select "Add... New Item", then choose SpriteFont. Then, simply change the name field to "PreludeFLF". If PreludeFLF is installed on your computer, Content will build it into a SpriteFont for you at compile time. Here's some things to know about XNA content: 1) Content is built on your PC, not on the phone. Binary, compiled content files (.xnbs) are transfered to the phone when you deploy. 2) The fonts you use do not have to be installed anywhere other than your PC, because they're made into bitmaps at compile. 3) You need rights to use your font I think – A-Type Feb 25 '12 at 19:50