我已经尝试了一段时间,我相信我做的一切都是正确的(就代码而言):
SpriteFont font = Content.Load<SpriteFont>("Arial");
但是,然后我读到您需要使用我尝试过的工具编译字体,但它们都是从扩展名 *.spritefont 转换而来的。这似乎不在我的机器上,尽管经过一些研究,我确实设法获得了几个 TTF 文件。
一些进一步的研究表明,如果我从 VS 中选择“新文件”,我应该能够选择创建一个新的 spritefont。情况似乎并非如此,因为它不在 VS2012 或 13 的列表中。
我没有理由经常使用字体,所以我可能犯了一个明显的错误。有什么想法吗?
最佳答案
好的,以下是您需要了解的内容的简要说明:
之后你的代码应该可以工作。这是一个具有上述最低限度的示例项目:
https://dl.dropboxusercontent.com/u/82020056/MonoGameSpriteFonts.zip
或者,还有一个选项可以完全跳过 XNA Content 项目并使用带有原始 Assets 文件的 MonoGame。这就是我在游戏中的做法,您可以找到 a tutorial on my blog .
编辑:我认为这很重要,可以包含在答案中; MonoGame 团队目前正在研究解决方案,以便不需要 XNA Game Studio。看起来字体已经被覆盖了。
https://github.com/mono/MonoGame/wiki/Content-Build-Pipeline
A port of XNA 4.0's Content Build Pipeline is currently in development. This will allow assets to be compiled into optimized binary formats for all platforms supported by MonoGame without requiring XNA Game Studio 4.0 to be installed on a Windows PC. The asset compiling will be done when the project is built, and supported in both Visual Studio (2010 and 2012) and MonoDevelop (Windows, Mac OS X and Linux).
关于.net - 在 VS2012/13 中使用 monogame 加载字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18268413/