MonoGame:无法加载资产

问题描述 投票:0回答:1

我开始使用天前monogame编程C#。今天,我得到了,说“无法加载的资产作为非内容文件”的错误。下面的代码,我需要多大的帮助。清单纹理;

    public Game1()
        : base()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }
    protected override void Initialize()
    {
        base.Initialize();
    }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        // the below line errors
        textures.Add(Content.Load<Texture2D>("Lol"));

    }
    protected override void UnloadContent()
    {
    }
    protected override void Update(GameTime gameTime)
    {
        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        base.Draw(gameTime);
    }
}
c# assets monogame
1个回答
1
投票

解决了

  1. 创建下一个内容的子文件夹。
  2. 称之为“资产”
  3. 在图像文件并右键单击右键单击
  4. 属性 - >复制到输出 - >复制始终
  5. 进入主类,并设置RootDirectory为“Content.RootDirectory = @”内容\资产“;”

附: :每次你添加一个文件,重复第3和第4步

© www.soinside.com 2019 - 2024. All rights reserved.