in

WP7 XNA text input

image

I’ve seen a few queries of how to get text input into an XNA game on Windows Phone 7 – so I thought I’d show you how.

It is all very simple. All you need to do is call Guide.BeginShowKeyboardInput. This uses the IAsync pattern to provide asynchronous input to game play. To get the string result from the input ‘dialog’ you call Guide.EndShowKeyboardInput putting the output into a string variable and passing in your IAsync Result object.

The code for my simple demo is below:

 

 

 

  1. protected override void Update(GameTime gameTime)
  2. {
  3.     // Allows the game to exit
  4.     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  5.         this.Exit();
  6.  
  7.     if(!Guide.IsVisible)
  8.         if(input=="")
  9.             Guide.BeginShowKeyboardInput (PlayerIndex.One,"Enter a string","Hello world",".",delegate(IAsyncResult result) { input = Guide.EndShowKeyboardInput(result); }, null);
  10.  
  11.  
  12.  
  13.     // TODO: Add your update logic here
  14.  
  15.     base.Update(gameTime);
  16. }

The key line (excuse pun) is:

Guide.BeginShowKeyboardInput (PlayerIndex.One,"Enter a string","Hello world",".",delegate(IAsyncResult result) { input = Guide.EndShowKeyboardInput(result); }, null);

 

I’m using an anonymous method to implement the callback. This purely puts the result of Guide.EndShowKeyboardInput into the app level public string ‘input’.

I check for Guide.IsVisible because I am calling the Guide in the Update method for this demo – this gets called every 1/30th of a second. I only collect one input.

Digg This

» Trackbacks & Pingbacks

  1. Pingback from Twitter Trackbacks for WP7 XNA text input - wotudo [wotudo.net] on Topsy.com
  2. Your story was featured in Drigg! Here is the link to vote it up and promote it: uxaxa.org/.../WP7_XNA_text_input_wotudo

    Drigg — March 16, 2013 4:32 PM
  3. Regrettably, a lot of feel that tortoises normally attain the majority their own water specifications looking at the meals and this for that reason they cannot demand added mineral water. Russians turtles tend to be in fact used into the semi-arid surroundings

    pligg.com — April 6, 2013 10:34 PM
  4. ... מכוני הסרת משקפיים - האופציה הסרת משקפיים אריאל היא קילוף השכבה החיצונית של הקרנית לאחר טיפול הסרת משקפיים בלייזר תופעות לוואי. הסרת משקפיים לא קיים היום ומעולם לא חשבתי על ניתוח להסרת משקפיים תוצאו... WP7 XNA text input - wotudo ...

    הסרת משקפיים פורום — November 22, 2013 10:20 PM
  5. ... - אך לפני שקופצים על שולחן הניתוחים צריך לעבור מספר טיפולים זמן לתוצאות ועוד. - מומלץ לשאול לכמה תשלומים למי שאינו מתאים עלול להיגמר בתוצאות מאוד לא נעים. במידה והינכם מתכוונים לה... WP7 XNA text input - wotudo ...

    טיפולי לייזר לעור — March 30, 2014 10:23 AM
  6. WP7 XNA text input - wotudo

    click here for more info — October 24, 2014 9:27 PM
  7. WP7 XNA text input - wotudo

    hair conditioner — November 15, 2014 4:42 AM
Trackback url for this post:
http://wotudo.net/blogs/wotudo/trackback.ashx?PostID=1211

» Comments

    No comments yet. Be the first to comment!

» Leave a Comment

(required) 
(optional)
(required) 

Submit