【问题标题】:MonoGame: Cannot load assetsMonoGame:无法加载资产
【发布时间】:2019-02-05 22:59:14
【问题描述】:

我几天前开始使用 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. 在 Content one 下创建一个子文件夹。
    2. 称之为“资产”
    3. 右键单击图像文件并右键单击
    4. 属性 -> 复制到输出 -> 始终复制
    5. 进入主类,将RootDirectory设置为“Content.RootDirectory = @"Content\Assets";”

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 2021-09-19
      • 2020-06-19
      • 1970-01-01
      • 2020-04-28
      • 2021-05-10
      相关资源
      最近更新 更多