windowsfontsxnaspritefont

Xna text having extra space between characters


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.


Solution

  • 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).