XNa game: keyboard pop-up window Input

Source: Internet
Author: User

In xNa, if we need to input text, we need to use a soft keyboard. In xNa, guide is used to use a soft keyboard. beginshowkeyboardinput method, because the update of the game will be continuously executed, the guide is required. isvisible to check whether the pop-up input box is displayed.

Guide. beginshowkeyboardinput method parameters
Playerindex indicates the player ID. The mobile phone number is playerindex. One.
Title in the title input window
Description in the input window
Default text
Callback callback Method
Object To be transmitted by the State user

Guide. beginshowmessagebox
Title of the title window
Text in the text window
Buttons button
Buttons preset by foucsbutton
Icon
Callback callback Method
Object To be transmitted by the State user

 

Example

 Using  System; Using  System. Collections. Generic;  Using  System. LINQ;  Using  Microsoft. xNa. Framework;  Using  Microsoft. xNa. Framework. Audio;  Using  Microsoft. xNa. Framework. content;  Using  Microsoft. xNa. Framework. gamerservices;  Using  Microsoft. xNa. Framework. graphics; Using  Microsoft. xNa. Framework. input;  Using  Microsoft. xNa. Framework. Input. Touch;  Using  Microsoft. xNa. Framework. Media;  Namespace  Sipsample {  ///   <Summary>      ///  This is the main type for your game  ///   </Summary>      Public  Class  Game1: Microsoft. xNa. Framework. Game {graphicsdevicemanager graphics; spritebatch; spritefont;  String Siptitle = "  This is the title.  "  ;  String Sipdescription = "  This is the description that goes beneath the title.  "  ;  String Sipresult = "  You type stuff here.  "  ;  Public  Game1 () {graphics = New Graphicsdevicemanager ( This  ); Content. rootdirectory = "  Content  "  ; Targetelapsedtime = Timespan. fromticks (333333  );}  Protected   Override   Void  Initialize (){  Base  . Initialize ();}  Protected   Override   Void  Loadcontent () {spritebatch = New  Spritebatch (graphicsdevice); spritefont = Content. Load <spritefont> ( "  Spritefont1  "  );}  Protected   Override   Void  Unloadcontent (){}  ///   <Summary>          ///  Input completion callback Method  ///   </Summary>          ///  <Param name = "result"> </param>          Void  Keyboardcallback (iasyncresult result ){  String Retval = Guide. endshowkeyboardinput (result );  If (Retval! = Null  ) {Sipresult = Retval ;}}  Protected   Override   Void Update (gametime ){  If (Gamepad. getstate (playerindex. One). Buttons. Back = Buttonstate. Pressed)  This  . Exit ();  //  Display the SIP Touchcollection = Touchpanel. getstate ();  Foreach (Touchlocation touch In  Touchcollection ){  If (Touch. State = Touchlocationstate. Pressed)  If (! Guide. isvisible)  //  The soft keyboard input box is displayed.  Guide. beginshowkeyboardinput (playerindex. One, siptitle, sipdescription, sipresult, keyboardcallback,  New   Object  ());}  Base  . Update (gametime );}  Protected  Override   Void  Draw (gametime) {graphicsdevice. Clear (color. cornflowerblue );  //  Draw text on the Interface  Spritebatch. Begin (); spritebatch. drawstring (spritefont, sipresult,  New Vector2 {x = 50 , Y = 200  }, Color. Black); spritebatch. End ();  Base  . Draw (gametime );}}} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.