3
\$\begingroup\$

Am looking for a little help and trying to use SpriteFont in my XNA 4.0 game but the problem is am displaying to string
"This is a test" but all that's displayed on the screen is "This is st" so the "a te" are missing from the screen.

The space is there for the characters but the letters are not.

The code am using is:

spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
spriteBatch.DrawString(font,"this is a test",new Vector2(692,372),Color.White);
spriteBatch.Draw(texture,new Rectangle(0,0,100,100),Color.White);
spriteBatch.End();

Any help with this would be great!

\$\endgroup\$
5
  • \$\begingroup\$ This one baffles me, not sure how it can render a 't', but not render all of the 't's. Have you tried other strings? I'd be curious to see if there was a pattern of some sort. \$\endgroup\$
    – Nic Foster
    Jun 27, 2012 at 13:59
  • \$\begingroup\$ Are you experiencing this with all fonts or just a specific one? \$\endgroup\$
    – Dadgron
    Aug 8, 2012 at 10:56
  • \$\begingroup\$ Does it work if you uncaptialize the first T? \$\endgroup\$ Aug 8, 2012 at 14:05
  • \$\begingroup\$ Try checking out what PIX shows in the DrawString step of the process. Also have you tried using the default sorting mode (SpriteSortMode.Deferred)? \$\endgroup\$
    – ChrisC
    Sep 7, 2012 at 3:22
  • \$\begingroup\$ Do you mind uploading the project? I don't think this is enough information to work off of. \$\endgroup\$ Sep 7, 2012 at 3:48

2 Answers 2

2
\$\begingroup\$

It sounds like you need to modify your XML file that defines your spritefont.

You want to ensure that the DefaultCharacter and CharacterRegion tags are correct. Below are the ones that I use in my Block.spritefont file.

    <!--
The default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
    <DefaultCharacter>@</DefaultCharacter>

    <!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
    <CharacterRegions>
        <CharacterRegion>
            <Start>&#32;</Start>
            <End>&#126;</End>
        </CharacterRegion>
        <CharacterRegion>
            <Start>&#9;</Start> <!-- The tab character -->
            <End>&#9;</End>
        </CharacterRegion>
    </CharacterRegions>
\$\endgroup\$
2
  • \$\begingroup\$ Please note that he says that only the part this is st appears from the phrase this is a test, so it can't be a problem with the spritefont character regions. \$\endgroup\$
    – r2d2rigo
    Aug 8, 2012 at 7:52
  • 2
    \$\begingroup\$ When others search for this topic they are likely to need the answer I provided. \$\endgroup\$
    – Jim
    Aug 8, 2012 at 17:12
1
\$\begingroup\$

Found out if i change the SpriteSortMode to deferred then this sorts my issue with drawing fonts

\$\endgroup\$
1
  • \$\begingroup\$ Any idea why? \$\endgroup\$
    – Cypher
    Sep 12, 2012 at 20:13

You must log in to answer this question.

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