0
\$\begingroup\$

Basically, for our college project, we need to use a font in xna. The only problem is that we are not allowed to install it due to admin rights.

Is it possible to use and load the .xnb file that gets created as the font. Using spritefont gives errors as it searches for the font in windows.

(The .xnb file will be created on someones personal machine beforehand.)

\$\endgroup\$
6
  • \$\begingroup\$ Yes you can do that. The .spritefont gives error because its not compiled to .xnb. You could also use a spritesheet with a font, here is how I do it: code image. I made that spritesheet using BMFC tool \$\endgroup\$
    – dimitris93
    Apr 27, 2015 at 16:49
  • \$\begingroup\$ First you need to Call Font.Initialize() in your Initialize and Font.Texture = Content.Load<Texture2D>("FontSprite"); in your LoadContent method. Then you can call Font.DrawString(spriteBatch, "my text", 1.15f, new Vector2(100, 200), Color.Snow); in your Draw method. \$\endgroup\$
    – dimitris93
    Apr 27, 2015 at 17:08
  • \$\begingroup\$ This tool XNA Formatter can also compile .spritefont to .xnb but it seems like it requires XNA 4.0 installed, so that you have the content pipeline dependencies set. \$\endgroup\$
    – dimitris93
    Apr 27, 2015 at 17:38
  • \$\begingroup\$ I have the .xnb file. Is there no way of using it easily like I use a spritefont, or do I need to write a new class handling the font? \$\endgroup\$
    – Tom Cork
    Apr 27, 2015 at 18:23
  • \$\begingroup\$ .xnb is a compiled file, so no, of course you can't edit it. What would the purpose of it be then. What I showed you has nothing to do with .spritefont or .xnb. It is how you could use an image as a font. \$\endgroup\$
    – dimitris93
    Apr 27, 2015 at 20:45

1 Answer 1

1
\$\begingroup\$

Copy your compiled (.xnb) font file to your content. And make the same filename as .spritefont file.

If you can't compile any fonts, use third party applications compiling those files.

Edit: Spritefont files are used to explain to the compiler, how that .ttf file should be compiled. (font size, chars, etc.)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .