0

So I'm trying to load a SpriteFont in XNA using

Content.Load<SpriteFont>("Font");

And I put the .spritefont file in the content project. But when I try to run the program it says the file doesn't exist. I know this is has been asked before but nothing worked.

[EDIT] A similar thing happened too, when I tried to import a wav file using the same means, it says there is some error in the file. But it plays fine outside of Visual Studio. Also, in "Project/Bin/x86/Debug/Content" it saving the files as font_0.xnb. I know it's SUPPOSED to be .xnb, but it's supposed not have the "_0". So I think that's the problem, and if so. How do I fix it?

PLUS I tried doing the same thing in a different XNA project, the same thing happened. I reinstalled XNA as a last resort, nothing works! ARRGHH

Xephyr
  • 122
  • 1
  • 2
  • 9
  • My memory is the resources must be in a resource project. It's been long enough since I played with XNA and I never did much with it so I'm not sure, though. – Loren Pechtel Mar 21 '16 at 01:04
  • I don't get what you mean by resource project, although I probably should. And how to fix it? – Xephyr Mar 21 '16 at 12:35
  • I think Loren is just referring to the content project, which you mentioned using, so that aspect should be okay. What is the exact wording of the error you're getting and any codes that accompany it? Also, what is the name of the spritefont file that's in your content project in the solution explorer? – paste Mar 21 '16 at 18:46
  • The spritefont is just called "font." I tried different names though. Also, the exact error is An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in Microsoft.Xna.Framework.dll Additional information: Error loading "font". File not found. – Xephyr Mar 21 '16 at 21:01
  • Have you tried passing "font_0" as an argument in the Load<> method? – paste Mar 21 '16 at 23:09
  • Actually, yes! It works if I – Xephyr Mar 21 '16 at 23:11
  • 'm trying to load a bitmap photo. But if I try a SpriteFont it saysAdditional information: Error loading "font_0". File contains Microsoft.Xna.Framework.Content.Pipeline.Graphics.FontDescription but trying to load as Microsoft.Xna.Framework.Graphics.SpriteFont. – Xephyr Mar 21 '16 at 23:13
  • In your ProjectContent/obj/x86/Debug/ folder, there should be a file called ContentPipeline.xml. One of the Items in there should describe your font. Can you just tell me what's in those tags? (you can omit the Time) – paste Mar 21 '16 at 23:23
  • font.spritefont FontDescriptionImporter None C:\Users\***********\bin\x86\Debug\Content\font_0.xnb – Xephyr Mar 21 '16 at 23:29
  • Okay try this: Open up ProjectContent.contentproj (in your ProjectContent directory) in a text editor. There should be an ItemGroup involving your font. Make sure between the Compile tags you have font FontDescriptionImporter FontDescriptionProcessor. Then save it, and allow VS to reload the file and then try running. – paste Mar 21 '16 at 23:37
  • font FontDescriptionImporter FontDescriptionProcessor /> //Should this be it? I'm kinda confused. Also, there's an error saying: The element <#text> beneath element is unrecognized Thanks for trying to help! – Xephyr Mar 21 '16 at 23:56
  • The should be right after – paste Mar 22 '16 at 00:02
  • Ok, there is still that error though. – Xephyr Mar 22 '16 at 00:04
  • Okay. If you highlight font.spritefont in your solution explorer, what shows up in the Properties window? – paste Mar 22 '16 at 00:06
  • Build Action: Compile – Xephyr Mar 22 '16 at 00:13
  • File Name: font.spritefont, Copy to Output Directory: Do not copy. – Xephyr Mar 22 '16 at 00:14
  • No properties in a category "XNA Framework Content Pipeline"? – paste Mar 22 '16 at 00:20
  • No. I need more letters to post this comment. :-) – Xephyr Mar 22 '16 at 00:27
  • Someone else with a similar problem reinstalled and it was fixed. Are you using XNA 4? What version of VS? – paste Mar 22 '16 at 00:37
  • I'm using VS 2015 Community, with XNA 4.0. I tried re-installing XNA though. It didn't work. >:( – Xephyr Mar 22 '16 at 00:40
  • 1
    Have you ever been able to load a SpriteFont in XNA (in projects before this one)? Are you using this version of XNA: http://stackoverflow.com/questions/28008970/how-to-install-xna-in-visual-studio-2015-preview ? – paste Mar 22 '16 at 00:46
  • I have not been able to use SpriteFont before. I am downloading that one though. – Xephyr Mar 22 '16 at 00:50
  • It worked! You're REAL life saver! Anything I can do in return? – Xephyr Mar 22 '16 at 00:58
  • Oh good! I can post that as the answer to your question. You can mark it as the answer and upvote anything else I've said here that was helpful :) – paste Mar 22 '16 at 01:00

1 Answers1

1

Make sure you have the right version of XNA to go with your version of Visual Studio. If you have VS2015, installing this version of XNA should help: https://mxa.codeplex.com/releases/view/618279

paste
  • 350
  • 1
  • 10