开发者

XNA ContentLoadException

I'm starting to learn "some" XNA and - as expected - I've run into an obstacle pretty early.

  • I've created a WP7 XNA Game solution
  • I've removed the default content project
  • I've added my own content project "Sprites"
  • I've added 3x *.png files to the "Sprites" project (MyImage1.png, MyImage2.png, MyImage3.png)
  • I've added a Content reference, referencing the "Sprites" to the main game project

/**/

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

    logoTexture = Content.Load<Texture2D>("Sprites/MyImage1");

    // TODO: use this.Content to load your game content here    
}

I'm getting a ContentLoadException saying "not found" when trying to load one my *.png's

  • I did check the output directory, a "Sprites" subfolder containing *.xnb files is present
  • I did check the properties of the images, all are marked as Te开发者_如何转开发xture2Ds and have content importers and processors set to default XNA values

I'm pretty sure I'm making a common n00b'ish mistake, but I'm failing to see it, so I'd apreciate some guidance.

Problem Fixed

Content.RootDirectory = "Content"; // The cause of the problem

Regards


Why did you remove the content project?

My guess is that you need to set the RootDirectory

        Content.RootDirectory = "Content";

which BTW creates ContentManager object.


You should try the following path formatting instead:

".\\Sprites\\MyImage1"

According to MSDN, the path must be relative to the current directory. And the directory separator is '\'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜