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.

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
add comment

1 Answer

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
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.