C# 无法在XNA4中加载spriteFont

C# 无法在XNA4中加载spriteFont,c#,xna,C#,Xna,我在和XNA闲逛,我已经到了需要加载字体的部分。很简单,对吧 Font1 = Content.Load<SpriteFont>("Arial"); 如果您正在设置内容根目录(此行是默认模板的一部分),那么您发布的代码看起来很好: 如果您已正确地将.spritefont文件添加到内容项目中,并且该文件正在正确构建。检查可执行文件旁边的Content目录中是否正在创建Arial.xnb文件(在bin/Debug或bin/Release中,具体取决于构建目标) 如果仍然存在问题,请尝试创

我在和XNA闲逛,我已经到了需要加载字体的部分。很简单,对吧

Font1 = Content.Load<SpriteFont>("Arial");

如果您正在设置内容根目录(此行是默认模板的一部分),那么您发布的代码看起来很好:

如果您已正确地将
.spritefont
文件添加到内容项目中,并且该文件正在正确构建。检查可执行文件旁边的
Content
目录中是否正在创建
Arial.xnb
文件(在
bin/Debug
bin/Release
中,具体取决于构建目标)


如果仍然存在问题,请尝试创建一个新的XNA项目,并查看是否可以在其中使用字体。

确保将内容项目添加为主项目的内容引用。右键单击项目并选择“添加内容引用”。然后只需选择列出的内容项目。这将确保您的内容被实际复制。

为什么不使用SpriteFont纹理,在一幅图像中包含所有字母。通过这种方式,您可以显示其他计算机没有的字体。在向项目添加纹理后,请记住将ContentProcessor更改为Font Txture


您发布的所有内容都是我的解决方案中已有的内容。我开始了一个新项目,并复制了代码,它工作得很好。不确定发生了什么,但它现在可以正常工作了。Sacling可以在显示SpriteFont时产生伪影,但在这种情况下,您可以创建一些在游戏中使用的不同大小。请投票,因为它可以工作。从那以后,我在这方面遇到了很多麻烦,所以它越来越有吸引力。
<?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>Arial</FontName>

    <!--
    Size is a float value, measured in points. Modify this value to change
    the size of the font.
    -->
    <Size>14</Size>

    <!--
    Spacing is a float value, measured in pixels. Modify this value to change
    the amount of spacing in between characters.
    -->
    <Spacing>0</Spacing>

    <!--
    UseKerning controls the layout of the font. If this value is true, kerning information
    will be used when placing characters.
    -->
    <UseKerning>true</UseKerning>

    <!--
    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
    and "Bold, Italic", and are case sensitive.
    -->
    <Style>Regular</Style>

    <!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    -->
    <!-- <DefaultCharacter>*</DefaultCharacter> -->

    <!--
    CharacterRegions control what letters are available in the font. Every
    character from Start to End will be built and made available for drawing. The
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
    character set. The characters are ordered according to the Unicode standard.
    See the documentation for more information.
    -->
    <CharacterRegions>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>
Error loading "Arial". File not found.
Content.RootDirectory = "Content";