无法在任何地方找到答案,希望你们能提供帮助,谢谢先进。 它们被加载到文件的开头 -
SpriteBatch mBatch;
Texture2D mTheQuantumBros2;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
mBatch = new SpriteBatch(this.graphics.GraphicsDevice);
//Create the Content Manager object to load images
ContentManager aLoader = new ContentManager(this.Services);
//Use the Content Manager to load the Cat Creature image into the Texture2D object
mTheQuantumBros2 = aLoader.Load<Texture2D>("TheQuantumBros2") as Texture2D;
// TODO: use this.Content to load your game content here
}
错误表示找不到该文件。文件是TheQuantumBros2.png,我尝试在原始游戏区域和内容区域下加载。两者都没有工作,我把它们放在目录中,并将它们加载到Visual Studio上的游戏中。想法?
答案 0 :(得分:1)
可能会发生一些事情......
首先,我看到你正在尝试创建一个新的ContentManager。根据我的经验,使用“内置”管理器要容易得多。通常,它被称为'contentManager'或'Content',并在生成类'game1.cs'时创建。通常,最好只使用一个内容管理器。
这是要使用的正确内容管理器。在“Game1.cs”的构造函数中,它应该说Content.RootDirectory =“Content”。这告诉经理文件所在的位置。在您的代码中,这就是您所缺少的。它根本不知道在哪里查找文件。
请将此添加到您的代码中:
SpriteBatch mBatch;
Texture2D mTheQuantumBros2;
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
mBatch = new SpriteBatch(this.graphics.GraphicsDevice);
//Create the Content Manager object to load images
ContentManager aLoader = new ContentManager(this.Services);
//ADD THIS
aLoader.RootDirectory = "Content";
//Use the Content Manager to load the Cat Creature image into the Texture2D object
mTheQuantumBros2 = aLoader.Load<Texture2D>("TheQuantumBros2") as Texture2D;
// TODO: use this.Content to load your game content here
}