brian_tsim


Hi all,

i finded xna "XNA Onscreen Keyboard Component" sample in internet(http://www.xnaresources.com/pages.asp pageid=27). What does the iFontAsciiStart and iFontAsciiEnd mean in function WriteText () Please somebody help. Below is the function coding.

public void WriteText(SpriteBatch spriteBatch, string sTextOut, int x, int y, Color colorTint)
{
// Very simple text output method. Uses a mono-spaced font to keep things easy
int iFontX = 0;
int iFontY = 0;
int iFontHeight = 30;
int iFontWidth = 19;
int iFontAsciiStart = 32;
int iFontAsciiEnd = 126;
int iOutChar;
for (int i = 0; i < sTextOut.Length; i++)
{
iOutChar = (int)sTextOutIdea;
if ((iOutChar >= iFontAsciiStart) & (iOutChar <= iFontAsciiEnd))
{
spriteBatch.Draw( t2dFont,
new Rectangle( x + (iFontWidth * i), y, iFontWidth-1, iFontHeight),
new Rectangle( iFontX + ((iOutChar - iFontAsciiStart) * iFontWidth),
iFontY, iFontWidth-1, iFontHeight),
colorTint
);
}
}
}

Best Regrads,




Re: XNA sample code problem ?

The ZMan


Moved to XNA forum but you should try reposting in the new forums http://creators.xna.com






Re: XNA sample code problem ?

Jim Perry

brian_tsim wrote:
What does the iFontAsciiStart and iFontAsciiEnd mean in function WriteText ()

This is ensuring that the character being rendered is one that can actually be rendered. Only certain characters can be rendered - A-Z, 1-0, etc. Special characters cannot be rendered with the code.