【问题标题】:Monogame "Could not find font file" when runningMonogame运行时“找不到字体文件”
【发布时间】:2022-09-26 05:59:53
【问题描述】:

我正在尝试学习 Monogame 的基础知识,并且我已经成功地弄清楚了如何使用 Monogame Content Pipeline 在屏幕上加载和显示图像。当我尝试对字体做同样的事情时,通过将名为 galleryFont.spritefont 的字体加载到 Monogame 内容管道中,一切都很好。

请注意:甚至在我将字体导入我的代码之前,我都会收到错误消息。

但是,当我运行项目时会出现问题。我收到如下所示的错误:

它指出:

错误:处理器“FontDescriptionProcessor”出现意外故障! System.IO.FileNotFoundException: 找不到 \"Arial\" 字体文件

我的构建任务也出现错误,说明如下:

正如您所看到的,文件已加载,但我注意到奇怪的是,monogame 内容管道没有将文件保存为.xnb 文件夹中的.xnb 文件。

或者由于错误说“找不到 Arial 字体文件”,这是否意味着我需要以某种方式下载 Arial font.ttf 并以某种方式将其链接到我的 .spritefont 文件中?如果有人感兴趣,这里是.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>24</Size>
    <Spacing>0</Spacing>
    <UseKerning>true</UseKerning>
    <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>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>

谢谢你的帮助。

  • 向我们展示您正在使用加载字体的代码。这就是问题所在。
  • @Frecklefoot 我收到错误甚至在我在代码中加载字体之前。我相信问题出在 mgcb-editor 上,因为 font.xml 没有出现。我还添加了在构建项目时发现的另一个错误。

标签: linux visual-studio-code fonts monogame


【解决方案1】:

经过大量研究后,我发现字体并没有自然地加载到我的计算机上。我使用的教程不知何故已经加载了 Arial 字体,所以他们可以使用 &lt;FontName&gt;Arial&lt;/FontName&gt; 来加载字体。但是,我必须下载字体,将其放入我的Content 目录,然后将.spritefont 文件编辑为&lt;FontName&gt;font.ttf&lt;/FontName&gt;。最后,完成此操作后,项目将运行。

【讨论】:

    【解决方案2】:

    当您将字体命名为“galleryFont”时,您似乎正在尝试加载“Arial”字体。尝试将其更改为代码中的那个,看看会发生什么。例如,这是我在我的一个游戏中加载字体的方式:

    protected override void LoadContent()
    {
       SpriteFont _font;
       _font = Content.Load<SpriteFont>("SuperArial");
    }
    

    “SuperArial”是我将 Arial 字体命名为我打包到我的mgcb 文件中的名称。

    【讨论】:

      【解决方案3】:

      Arial 特定于 Windows。

      Linux 用户可以通过以下方式使用这些字体的一个版本:

      Ubuntu(与 deb 相同的软件包)

      sudo apt install ttf-mscorefonts-installer`
      

      拱:

      sudo yay -S ttf-ms-fonts ttf-vista-fonts ttf-office-2007-fonts ttf-win7-fonts ttf-ms-win8 ttf-ms-win10 ttf-ms-win11`
      

      红色的帽子:

      sudo rpm -i https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
      

      所有这些方法都注册了字体,并且可以按指定直接使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-14
        • 1970-01-01
        • 2017-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-08
        • 1970-01-01
        相关资源
        最近更新 更多