Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for some help how to add text in XNA? I'm doing a game where I want the player to enter his or her name in the beginning. Is ther a simple way to do this? Help is preciated! Thanks!

share|improve this question
up vote 2 down vote accepted

Had a post dedicated to this on my blog. I need to set my server back up :/

Anyways keyboard input in XNA is very poorly supported. Many including myself prefer to use a windows form event hook. This makes things very simple. Code below is very C#ish pseudocode off the top of my head so you may need to tweak it.

// Just draw this string
string text = "";

//Add an event for a character being added
InputSystem.CharEntered += delegate(Object o, CharacterEventArgs e) {
    if (Font.Characters.Contains(character)) {
        text += e.Character;
    } else if (e.Character == '\b' /* backspace */) {
        if (text.lenght > 0 ) { text = text.substring(0, text.lenght - 1); }

Unfortunately the above only works on the pc, though it sounds like that is your development environmental.

If you will need additional GUI controls it might be worth downloading a 3rd party library such as Neoforce, XNAGui (Mine), or Nuclex.

share|improve this answer
Thanks! Looks complicated, but will try it later! – 3D-kreativ Aug 26 '12 at 7:27

Your Answer


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.