简体   繁体   English

如何在iOS / Android上创建文本框并在MonoGame中处理输入?

[英]How can I create a text box on iOS/Android and handle the input in MonoGame?

I want that people can create a new account in my MonoGame iOS and Android application. 我希望人们可以在我的MonoGame iOS和Android应用程序中创建一个新帐户。 I need a text box for username, password and recovery e-mail address (if someone forgot his password). 我需要一个用于用户名,密码和恢复电子邮件地址的文本框(如果有人忘记了他的密码)。

  • How can I create the text box? 如何创建文本框? Should I make a white rectangle sprite ( Texture2D ) and a spriteFont to write the text (for example the username)? 我应该制作一个白色矩形精灵( Texture2D )和一个spriteFont来写文本(例如用户名)? Or are there better ways to create the text box? 或者有更好的方法来创建文本框?

  • How can I find out if someone tapped with his finger on the blank text box? 如何判断是否有人用手指轻拍空白文本框? Can I use Rectangle.Intersects(TappRectangle) or is it better to do this differently? 我可以使用Rectangle.Intersects(TappRectangle)还是以不同的方式做到这一点?

  • How can I show the keyboard on iOS/Android after someone tapped on the text box so that they can write their username in the textbox? 在有人点击文本框后,如何在iOS / Android上显示键盘,以便他们可以在文本框中编写用户名?

  • How can I get the characters they tapped on the keyboard? 如何获取他们在键盘上敲击的角色?

  • Is it possible to save/remember the text(login data) so that people don't need to write it always when they start my application? 是否可以保存/记住文本(登录数据),以便人们在启动应用程序时不需要总是编写它? I want that the text boxes are already filled out with their login credentials when they start the application, then they would just need to tap on a login button to log in. 我希望文本框在启动应用程序时已经填写了登录凭据,然后他们只需点击登录按钮即可登录。

You can use the KeyboardInput.Show(string WindowTitle, string Prompt, string Default, bool HidePassword = false) method. 您可以使用KeyboardInput.Show(string WindowTitle, string Prompt, string Default, bool HidePassword = false)方法。

// Load saved data into the following variables:
var defaultUsername = "";
var defaultPassword = "";
var defaultEmail = "";

var username = await KeyboardInput.Show("Name", "What's your username?", defaultUsername);
var password = await KeyboardInput.Show("Password", "What's your Password?", defaultPassword, true);
var email = await KeyboardInput.Show("E-Mail", "What's your Email?", defaultEmail);

// validate and save if the values do not match the defaults above

This will show three separate input boxes, but it handles prompts and pop-up keyboard display and input. 这将显示三个单独的输入框,但它会处理提示和弹出键盘显示和输入。

As far as saving the data: Look at the TitleContainer class. 至于保存数据:查看TitleContainer类。 You can use standard file I/O to read and write the data. 您可以使用标准文件I / O来读取和写入数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM