The Code-Bin
XNA Simple Text Box
Posted by: Quimby RBG | April 18, 2011 @ 12:47am

C# Code



Syntax Highlighting





Author Comments
~Requires Microsoft XNA 4.0~
(though probably fine with older)
This is a quick and easy text box I did up when I found out I had to ditch the GamerServices Keyboard input for getting names for my high scores table.
The max character setting is handy for high score tables as having a finite number of characters will prevent it running off the screen.
The rectangle for where it is to be drawn is exposed so you can check it against mouse clicks or, as I did, draw a "X Characters remaining" string centred below the text box.
((X+(Width/2))-font.measurestring(string).x/2)
You can update it every turn and it will only update if it is active, but I find Active useful to check against to use as a "User just confirmed text box entry" prompt by using if(Textbox.Active){Textbox.Update();}else{Do Something}

Have fun; It's pretty basic, but hopefully it might save you some time if you just want a quick alphanumeric input. :)

Quimby ~ RBG Entertainment
Rating


4.77 / 8
35 Votes