我的游戏的编辑框?
我正在创建一个 Android 游戏。目前我正在使用“普通”视图和绘图、onDraw() 并有一个处理程序来处理定时事件等。然而很快(tm)我会将其转换为带有线程和常量循环的 SurfaceView。
无论如何,当玩家按下某个按钮时,我希望有一种编辑框供玩家输入值(价格)。但我对如何实现这一目标有点迷失。首先我想,好吧,让我们创建一个 EditText,将其放置在屏幕上,然后就完成了。但显然我不能只是将 EditText 放在 X,Y 位置然后再将其删除。
我查看了 LunarLander 示例,它使用 TextView 来显示文本。它已在布局 XML 中定义,并通过在游戏线程和 UI 线程之间发送消息来使其可见和不可见。这看起来非常复杂,并且编辑框始终存在。
此外,我正在考虑制作自己的“编辑框”,只需在屏幕上绘制一个框,启用键盘,然后捕获来自键盘的输入。但我什至不知道从哪里开始“自定义”键盘输入(屏幕上与物理上,如何捕获键盘文本输入,完成后如何再次隐藏键盘等)。
所以我想知道,最好的方法是什么?
编辑:也许知道有用,但我的游戏已修复为横向模式。
I am creating an Android game. Currently I'm using a "normal" View and draw, the onDraw() and have a Handler to process timed events and such. However Soon (tm) I will convert it to a SurfaceView with a Thread and a constant loop.
Anyway, when the player presses a certain button, I want to have a kind of edit box for the player to enter a value (a price). But I'm kind of lost on how to achieve this. First I thought, ok let's just make an EditText, position it on the screen, and done. But apparently I can't just put an EditText on an X,Y location and remove it afterwards.
I looked at the LunarLander example, which uses a TextView for displaying text. It is already defined in the layout XML and is turned visible and invisible by sending messages between the game thread and the UI thread. This seems awefully complicated and the edit box would exist all the time.
Furthermore I was thinking on making my own "edit box" by simply drawing a box on the screen, enabling the keyboard, and then capturing input from the keyboard. But I wouldn't even know where to begin with "custom" keyboard input (on screen vs physical, how to capture keyboard text input, how to hide the keyboard again when done, etc).
So I was wondering, what's the best way to do this?
Edit: maybe useful to know, but my game is fixed in landscape mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弹出一个对话框,其中包含一些精美的图形,其中包含 EditText,怎么样?
如果您想坚持只使用 SurfaceView,那么您可能必须实现自己的简单 GUI 系统。我环顾四周,也许有一些适用于 Android 游戏的 GUI 库。
How about popping up a dialog box with some fancy graphics with the EditText in it?
If you want to stick to using only the SurfaceView, then you may have to implement your own simple GUI system. I'd look around, maybe there're some GUI libs out there for android games.