Could not load content1.png asset as non content file

白昼怎懂夜的黑 提交于 2019-12-12 08:32:15

问题


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.


回答1:


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




回答2:


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.




回答3:


In MonoGame 3.5.1 you must use MonoGame pipeline tool for your resources, and include builded *.mgcb file to your content folder in project. See sample project Platformer2d.

MonoGame pipeline tool http://www.monogame.net/2016/03/17/monogame-3-5/

Samples https://github.com/MonoGame/MonoGame.Samples



来源:https://stackoverflow.com/questions/20760828/could-not-load-content1-png-asset-as-non-content-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!