1

I'm making a new game, and I want to use my own textures for texts. I came across this cool tool called SpriteFont 2.0, which is like a WYSIWYG editor for making texture files for SpriteFont files in XNA. I made this font:My font texture

But my problem is that when I put it into XNA, there is A LOT of extra space between letters. For example, this was supposed to say, "This is a test", but it turned out like this:enter image description here

Is there something wrong with my texture file, or is there something I need to do with my programming. I just used the first DrawString method in the SpriteBatch object. I changed the Content import for the texture file to Sprite Font Texture, too. I don't know why the text has so much space between characters.

alvonellos
  • 1,009
  • 1
  • 9
  • 27
pjrader1
  • 491
  • 7
  • 22

1 Answers1

4

You could change the Spacing property of your SpriteFont object at runtime. Set it to a negative value and see if the letters are closer together.

SpriteFont myFont = ...;
myFont.Spacing = -10;

Alternately, if the editor has kerning settings, that's what you would really want. Kerning is defining the spacing between letters, like so:

Kerning example


There is also a LineSpacing property for vertical height which you might also want to tweak, if you print multiple lines to the screen (as one draw call).

Ricket
  • 33,368
  • 30
  • 112
  • 143
  • 1
    But Im not using a .spritefont file. You can make a font texture inside a paint editor, sort of like a sprite sheet. Then just change the way Visual Studio builds it. Because all that Visual Studio does with the .spritefont files is turn them into Bitmaps. SpriteFont 2.0 has a spacing property, but that doesnt change anything, as far as I can see. – pjrader1 Oct 04 '12 at 03:00
  • @cakeisajoke Unfortunately the build-time settings for `SpriteFont`s are very limited. But what Ricket has linked are **runtime** settings. Which you can set on your `SpriteFont` object after you load it... With a bit of trickery you can build custom `SpriteFont` content - with full control over spacing, kerning, etc - even though there's no official way in XNA. Look at Nuclex Fonts for an example. But it's rather complicated - so the runtime solution is probably your best bet. – Andrew Russell Oct 04 '12 at 07:55
  • Of course, what @Ricket wrote about modifying `.spritefont` files doesn't apply to your question at all. And there's no runtime way to modify the kerning setting. Perhaps an edit, Ricket? – Andrew Russell Oct 04 '12 at 07:57
  • @cakeisajoke As Andrew pointed out, Spacing is also a runtime property. I edited to show an example of how you'd set it. Maybe it'll work for you? – Ricket Oct 04 '12 at 12:25
  • Hey! Your right, I can change some of the SpriteFont properties by changing the variable I load it in. Thanks! – pjrader1 Oct 05 '12 at 02:50