没有找到文件
本文关键字:文件 | 更新日期: 2023-09-27 18:12:51
在任何地方都找不到答案,希望你们能帮助,提前感谢。这些都加载在文件的开头-
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上的游戏中。想法吗?
可能会发生一些事情…
首先,我看到你正在尝试创建一个新的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
}