Android - 通过触摸在游戏板上选择图块?
我正在开发 Android 跳棋应用程序。我在 Canvas 游戏板上绘制了每一面的图块,并且我还通过 D-Pad 选择了图块。但是,Android 手机没有方向键怎么办?必须有一种方法可以在触摸中做到这一点(我触摸一个图块 - 现在它已被选中)。你有什么想法吗?
谢谢
我的游戏板图片可以在这里找到 - http://img171.imageshack.us/img171 /7814/跳棋.gif
i am developing checkers application for Android. I have drawn on Canvas gameboard and tiles for each side, also I have made selection of tiles by D-Pad. But what about, Android phone doesn't have D-Pad? There must be a way how to do that in touch (I touch a tile - it is selected now). Do you have any ideas?
Thanks
image of my Gameboard can be found here - http://img171.imageshack.us/img171/7814/checkers.gif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种(更简单?)替代方法是使用 Android 的标准 Button/ImageButton。如果您不希望显示默认边框,您可以自定义其边框和内容。
标准按钮可与触摸板和方向键配合使用;因此您可以减少使图块在这两种情况下都能正常运行所需的编码量。
Another (easier?) alternative is to use Android's standard Button/ImageButton. You can customize its border and content, if you don't want the default border to show up.
The standard Buttons works with both touch and D-pad; so you can cut the amount of coding you need to make tiles that behave properly under both situations.
将图块位置存储在二维数组中。在手指按下事件中,检查每个图块的事件位置。当您找到被戳的图块时,选择它。
Store tile locations in a 2d Array. On the finger down event, check the event location against each tile. When you find the tile that was poked, select it.