Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单游戏Windows OpenGL项目“;无法将资产作为非内容文件加载";资源设置为“始终复制”_C#_Exception_Assets_Monogame - Fatal编程技术网

C# 单游戏Windows OpenGL项目“;无法将资产作为非内容文件加载";资源设置为“始终复制”

C# 单游戏Windows OpenGL项目“;无法将资产作为非内容文件加载";资源设置为“始终复制”,c#,exception,assets,monogame,C#,Exception,Assets,Monogame,最近,我在将资产加载为Texture2D时遇到了一些问题。我已尝试将路径更改为“.\assetName”、“assetName”、“assetName.png”和“.\assetName.png”(正如问题的一个答案所建议的那样,但这两个选项都不起作用。我还尝试在添加文件时使用MonoGame内容管道,“复制到输出目录”参数当前设置为“始终复制” 我试着用一些非常简单的代码创建一个新项目来加载内容文件,内容如下 using Microsoft.Xna.Framework; using Micro

最近,我在将资产加载为Texture2D时遇到了一些问题。我已尝试将路径更改为“.\assetName”、“assetName”、“assetName.png”和“.\assetName.png”(正如问题的一个答案所建议的那样,但这两个选项都不起作用。我还尝试在添加文件时使用MonoGame内容管道,“复制到输出目录”参数当前设置为“始终复制”

我试着用一些非常简单的代码创建一个新项目来加载内容文件,内容如下

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace TempSol2
{
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
    Texture2D texture;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: use this.Content to load your game content here
        texture = Content.Load<Texture2D>("Character1");
    }
使用Microsoft.Xna.Framework;
使用Microsoft.Xna.Framework.Graphics;
使用Microsoft.Xna.Framework.Input;
名称空间TempSol2
{
/// 
///这是游戏的主要类型。
/// 
公共类游戏1:游戏
{
图形管理器图形;
SpriteBatch SpriteBatch;
纹理2D纹理;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
//TODO:在此处添加初始化逻辑
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
纹理=内容。加载(“字符1”);
}
但我每次都会犯同样的错误

异常消息的内容如下:标题为“无法将Character1资产作为非内容文件加载”,内部异常为“未找到内容文件”


我还检查了文件应该复制到的文件夹,其中包含.png和.xnb。MonoGame团队已经引入了一种新的更好的方法,通过使用MonoGame管道应用程序来管理项目中的内容

要正确添加精灵,请首先使用MonoGame管道工具打开Content.mgcb文件(您应该在安装MonoGame的地方找到它)

然后从编辑菜单中,添加>现有项,并选择您的图像

建立内容,你应该是好去

 spriteBatch.Begin();
 spriteBatch.Draw(texture,Vector2.Zero,Color.White);
 spriteBatch.End();
阅读有关从管理内容的更多信息

编辑 要加载精灵,请使用完全相同的方法

  protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: use this.Content to load your game content here
        texture = Content.Load<Texture2D>("Character1");
    }
protected override void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
纹理=内容。加载(“字符1”);
}

MonoGame团队引入了一种新的、更好的方法,通过使用MonoGame管道应用程序来管理项目中的内容

要正确添加精灵,请首先使用MonoGame管道工具打开Content.mgcb文件(您应该在安装MonoGame的地方找到它)

然后从编辑菜单中,添加>现有项,并选择您的图像

建立内容,你应该是好去

 spriteBatch.Begin();
 spriteBatch.Draw(texture,Vector2.Zero,Color.White);
 spriteBatch.End();
阅读有关从管理内容的更多信息

编辑 要加载精灵,请使用完全相同的方法

  protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: use this.Content to load your game content here
        texture = Content.Load<Texture2D>("Character1");
    }
protected override void LoadContent()
{
//创建一个新的SpriteBatch,可用于绘制纹理。
spriteBatch=新spriteBatch(图形设备);
//TODO:使用此.Content在此处加载游戏内容
纹理=内容。加载(“字符1”);
}

你忘了提到如何加载内容我实际上试图在手机上编辑它,但显然效果不太好。你忘了提到如何加载内容我实际上试图在手机上编辑它,但显然效果不太好。