Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load content1.png asset as non content file

When trying to import an image into my 'game' I get a error message. The one displayed in the title. it is called content1.png and is in the Content folder. I have

public override void LoadContent()
{
    base.LoadContent();
    path = "Content/content1.png";
    splash1 = content.Load<Texture2D>(path);
}

and it doesn't load it.
I have no idea what to do here.

like image 378
stepper Avatar asked Dec 24 '13 12:12

stepper


2 Answers

It's seems like the content.Load<Texture2D> method tries to open the file from your File-System and it is not founded there, do the following to solve it:

In Visual Studio -> Right-Click on the content1.png file -> Select Properties ->

  • Set the Build-Action to "Content" in the properties window for content1.png.

  • Set the Copy to Output Directory to -> Always

like image 195
Yair Nevet Avatar answered Sep 23 '22 12:09

Yair Nevet


While the accepted solution didn't work for me, I finally figured out that it was the relative path of the asset that was creating problems, so changing

Content.Load<Texture2D>("Graphics\\MyAsset.png")

to

Content.Load<Texture2D>("..\\Graphics\\MyAsset.png")

did the trick for me.

like image 2
dotNET Avatar answered Sep 23 '22 12:09

dotNET