2 Replies - 761 Views - Last Post: 04 March 2017 - 08:57 PM

#1 Hydropulse17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-March 17

Could not load asset as a non-content file!

Posted 04 March 2017 - 05:14 PM

Wait, I know what you're going to say, "the internet is littered with this question, do your research."

This is driving me nuts. When I Google this question I see the same solutions repeated over and over again but none seem to apply to me.

They mention the properties on the files, all of mine are set to Content and copy if newer.

They mention the file extension, I'm using XNBs made from the Monogame content pipeline out of PNGs.

They also mention the folders. Now, this is the first area that I think I might be making a mistake. I think it's disgusting that there are so many folders named content and bin and whatnot inside the program directory, but I digress. I like to be organised, and having hundreds of images inside a folder called Graphics doesn't sit with me. I have all 62 sprites for one animation for my robo/player in a director like Content/Graphics/Robo/RunAnim. I've played with the coded directories, I've moved the content around, I just can't figure it out.

One other reason I might be struggling is because I'm trying to load content in my Player class. I mean, the player load content method is called in the Game load content method still.

Here is my code.

public void LoadContent(ContentManager contentManager)
        {
            string[] files = Directory.GetFiles("Content\\Graphics\\Robo\\RunAnim");
          
            //iterating through the files in RunAnim

            for (int i = 0; i < files.Length; i++)
            {
                roboRunAnim.Add(contentManager.Load<Texture2D>(files[i].Remove(0, @"Graphics\Robo\RunAnim".Length)));
            }
        }


And it's called like this, in the load content method of the Game1 class.

player.LoadContent(Content);


Is This A Good Question/Topic? 0
  • +

Replies To: Could not load asset as a non-content file!

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13383
  • View blog
  • Posts: 53,409
  • Joined: 12-June 08

Re: Could not load asset as a non-content file!

Posted 04 March 2017 - 07:57 PM

Quote

I have all 62 sprites for one animation for my robo/player in a director like Content/Graphics/Robo/RunAnim.

Then make sprite sheets.
Example:
http://www.dreaminco...nimated-sprite/

Quote

"the internet is littered with this question, do your research."

What, exactly, is your question?
Was This Post Helpful? 0
  • +
  • -

#3 Hydropulse17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-March 17

Re: Could not load asset as a non-content file!

Posted 04 March 2017 - 08:57 PM

I'd be having the problem with a sprite sheet still I imagine, as it would still be a single xnb from a png, right? And I guess the question would be "How to I make it correctly load the content?"

Anyways, I figured it out just now, sort of. The exact error message was saying that it could not load RoboRun_000.xnb as a non-content file, which is the exact name of my file, so I don't understand why my previous code didn't work when my new one does. This one is simpler to follow though, so I won't complain.

string[] files = Directory.GetFiles("Content\\Graphics\\Robo\\RunAnim");  

            for (int i = 0; i < files.Length; i++)
            {
                roboRunAnim.Add(contentManager.Load<Texture2D>(@"Graphics\Robo\RunAnim\RoboRun_" + i.ToString("D3")));
            }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1