Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
    
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. –  Nic Foster Jun 27 '12 at 13:59
    
Are you experiencing this with all fonts or just a specific one? –  Aaron Kabashi Aug 8 '12 at 10:56
    
Does it work if you uncaptialize the first T? –  Vaughan Hilts Aug 8 '12 at 14:05
    
Try checking out what PIX shows in the DrawString step of the process. Also have you tried using the default sorting mode (SpriteSortMode.Deferred)? –  ChrisC Sep 7 '12 at 3:22
    
Do you mind uploading the project? I don't think this is enough information to work off of. –  ClassicThunder Sep 7 '12 at 3:48
add comment

2 Answers

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>
share|improve this answer
    
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. –  r2d2rigo Aug 8 '12 at 7:52
2  
When others search for this topic they are likely to need the answer I provided. –  Jim Aug 8 '12 at 17:12
add comment

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

share|improve this answer
    
Any idea why? –  Cypher Sep 12 '12 at 20:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.