Loading images in XNA 4.0; "Cannot Open File" Problems

Posted by user32623 on Game Development See other posts from Game Development or by user32623
Published on 2013-06-30T08:08:33Z Indexed on 2013/06/30 10:28 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

Okay, I'm writing a game in C#/XNA 4.0 and am utterly stumped at my current juncture: Sprite animation. I understand how it works and have all the code in place, but my ContentLoader won't open my file...

Basically, my directory looks like this:

    //WindowsGame1
      - "Game1.cs"
      - //Classes
          - "NPC.cs"
      - Content Reference
          - //Images
              - "Monster.png"

Inside my NPC class, I have all the essential drawing functions, i.e. LoadContent, Draw, Update. And I can get the game to find the correct file and attempt to open it, but when it tries, it throws an exception and tells me it can't open the file. This is how my code in my NPC class looks:

    Texture2D NPCImage;
    Vector2 NPCPosition;
    Animation NPCAnimation = new Animation();

    public void Initialize()
    {
        NPCAnimation.Initialize(NPCPosition, new Vector2(4, 4));
    }

    public void LoadContent(ContentManager Content)
    {
        NPCImage = Content.Load<Texture2D>("_InsertImageFilePathHere_");
        NPCAnimation.AnimationImage = NPCImage;
    }

The rest of the code is irrelevant at this point because I can't even get the image to load. I think it might have to do with a directory problem, but I also know little to nothing about spriting or working with images or animations in my code. Any help is appreciated. Not sure if I provided enough information here, so let me know if more is needed! Also, what would be the correct way to direct that Content.Load to Monster.png given the current directory situation? Right now I just have it using the full path from the C:// drive. Thanks in advance!

© Game Development or respective owner

Related posts about XNA

Related posts about c#