我正在尝试学习 Monogame 的基础知识,并且我已经成功地弄清楚了如何使用 Monogame 内容管道在屏幕上加载和显示图像。当我尝试对字体执行相同操作时,通过将名为 galleryFont.spritefont
的字体加载到 Monogame 内容管道中,一切都很好。
请注意:甚至在将字体导入代码之前,我都会收到错误。
但是,当我运行项目时,出现了问题。我收到如下错误:
它指出:
error : Processor 'FontDescriptionProcessor' had unexpected failure! System.IO.FileNotFoundException: Could not find "Arial" font file
我的构建任务中也出现错误,说明如下:
正如您所看到的,文件已加载,但我注意到奇怪的是单游戏内容管道没有将文件保存为 中的
文件夹。.xnb
文件Content/bin
或者由于错误显示“无法找到 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> </Start>
<End>~</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
感谢您的帮助。
最佳答案
经过大量研究后,我发现该字体并未自然加载到我的计算机上。我使用的教程不知何故已经加载了 Arial 字体,所以他们可以只使用 <FontName>Arial</FontName>
加载字体。但是,我必须下载一种字体,将其放入我的 Content
中目录,然后编辑 .spritefont
文件至<FontName>font.ttf</FontName>
。最后,完成此操作后,项目就可以运行了。
关于linux - 运行时Monogame "Could not find font file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73583464/