1

I am making game in xna and now I need to take some input like name and gender. It would be much easier if I was using C# but I don't know how to do this here.

halfer
  • 19,824
  • 17
  • 99
  • 186

4 Answers4

4

You are using C# when you're using XNA. The XNA framework is just a set of dlls that you program against using C#.

As for taking input, you can either code your own controls or use some existing libraries. Both options have their pros and cons.

We have a FAQ over on the XNA forums called "What GUI Systems are there for the XNA framework" that would probably be a useful read for you -> http://forums.create.msdn.com/forums/t/15274.aspx

George Clingerman
  • 1,395
  • 9
  • 15
0

If I were doing this, I would listen for some keys and then the "Enter" buttons. I would then repeat that as many times as I needed. The code for it is below.

KeyboardState key;
OldKeyboardState oldKey;
String input;
//Puts final input in this
String finalIn;
String finalIn2;
String finalIn3;

protected override void Update(GameTime gameTime)
{
    key = Keyboard.GetState();
    //Do for all acceptable characters
    if (key.IsKeyDown(Keys.A) && key.IsKeyDown(Keys.RightShift) && oldKey.IsKeyUp(Keys.A) && oldKey.IsKeyUp(Keys.RightShift)) input = input + "A";
    else if (key.IsKeyDown(Keys.A) && oldKey.IsKeyUp(Keys.A) input = input + "a";
    //Etc.
    //Finalize input when enter is pressed
    if(key.IsKeyDown(Keys.Enter) && oldKey.IsKeyUp(Keys.Enter))
    {
        finalIn = input;
        input = "";
    }
    //Finalize input when enter is pressed for second input
    if(key.IsKeyDown(Keys.Enter) && oldKey.IsKeyUp(Keys.Enter) && finalIn != "")
    {
        finalIn2 = input;
        input = "";
    }
    //Etc.
    //At end set oldKey = key, so we have the current one and the old one
    oldKey = key;
}
protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    //If desired, add in a draw string to show user what is being inputed
    base.Draw(gameTime);
}
SupremeSteak1
  • 136
  • 11
0

It's easier to implement your own controlls. Use spritebatch and register key strokes in a string buffer, then show it on the screen using spriebatch.DrawString(..)

Sup3rlum
  • 51
  • 7
0

Use an existing user interface library such as xWinForms. You can find more options in the UI library for XNA question.

Community
  • 1
  • 1
Empyrean
  • 1,823
  • 12
  • 10