Asset not found XNA

家住魔仙堡 提交于 2019-11-27 09:48:48

If you've added your file to the Content project (those are new for 4.0) the other things to check would be to make sure the file is one of the supported formats for a Texture2D (.jpg, .png, .bmp, .tga). After that, click on the image and verify that the asset name is correct and matching the exact casing/spelling that you're using in code to load it by that name. If that's correct then also make sure that the Content Importer for the image is set correctly to be a Texture2D. And then another thing to verify would be to make sure you're image is in the root of the Content project and not in a folder. If you have it in a folder, then you need to include the folder name (or names) when loading it.

If you've verified all that then you may need to post an image or a sample project so that we can take a look and see if we spot anything that way.

From that screenshot it looks like you need to right-click on the "Test" project and say "Add Content Reference". You'll then need to pick your "Test (Content)" project as that reference. That should have happened by default when you created this new game project and I'm not sure why it looks like it was removed.

As you are using Visual Studio 2010, I'm guessing that you are using XNA 4.0. If this is the case, there is a new Content Reference project where you put all of your textures, sounds, models etc. into. If you have created a Content folder in the XNA Game project, this won't work.

In XNA 4.0 Content Reference project has a Content Root Directory property (set to Content by default) that specifies the name of the subdirectory that will hold the final output files of pipeline content generated from the project folder. Therefore, if you create Content directory inside Content Reference project the Face asset will be placed in Content/Content directory and you will have to load it like this

mSpriteTexture = Content.Load<Texture2D>(@"Content/Face");

despite setting Content.RootDirectory = "Content"

Another potential solution:

Check your original file (e.g. MyTexture.bmp) and make sure the Build Action is set to Compile.

If you have it set to something else, such as the logical-seeming Content, it won't work.

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