0

找不到答案,希望各位大神帮忙,先谢谢了。这些被加载在文件的开头 -

    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 上的游戏中。想法?

4

1 回答 1

1

A few things could be happening...

Firstly, I see that you are are trying to make a new ContentManager. In my experience it is a lot easier to use the manager that is "built-in". Usually, it is either called 'contentManager', or 'Content' and is created when the class 'game1.cs' is generated. In general, it is best to simply use one content manager.

This is the correct content manager to use. In the constructor for "Game1.cs" it should say Content.RootDirectory = "Content". This tells the manager where the file is located. In your code, that is what you are missing. It simply does not know where to look for the file.

So add this to your code:

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
}
于 2013-05-09T14:44:59.640 回答