ContentLoadException 未处理 - 加载“Arial”时出错.找不到文件

本文关键字:出错 找不到 文件 Arial 未处理 加载 ContentLoadException | 更新日期: 2023-09-27 18:32:35

我试图在我的游戏中得分。但看起来加载器找不到字体 Arial。当我尝试运行游戏时,出现错误:"加载"Arial"时出错。找不到文件"

游戏1.cs:

HUD hud;
protected override void LoadContent()
{    
      hud = new HUD();
      hud.Font = Content.Load<SpriteFont>("Arial"); // error here
}

平视.cs:

public class HUD
    {
        private Vector2 scorePos = new Vector2(20, 10);
        public SpriteFont Font { get; set; }
        public int Score { get; set; }
        public HUD()
        {
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(
                Font,                   
                "Score: " + Score.ToString(),  
                scorePos,                      
                Color.White);                 
        }
    }

ContentLoadException 未处理 - 加载“Arial”时出错.找不到文件

XNA 要求在使用字体之前将字体显式添加到项目中。 也就是说,你不能使用"Arial",除非你已经将Arial .spritefont文件添加到你的项目中。

如果你使用的是XNA,你可以在这里阅读如何添加SpriteFont:

http://msdn.microsoft.com/en-us/library/bb447673.aspx

如果您使用的是MonoGame,则可以使用Pipeline工具添加SpriteFonts。 你可以在这里阅读它:

http://www.monogame.net/documentation/?page=Pipeline