Android - 是否可以在视图中动态移动可点击对象
出于游戏开发的目的,是否可以设置一个视图并创建一个扩展按钮或实现可点击之类的类。我试图找出处理屏幕上移动对象的屏幕点击的最佳方法,现在我在画布上绘制所有内容,而画布又被绘制到视图中,但我无法使表示对象的单个位图可单击。
因此,在我投入大量工作并尝试之前,是否有人知道是否可以在视图中动态移动对象来独立处理屏幕点击。
For the purposes of say game development, is it possible to set up a view and create a class that extends button or implements clickable or something. Im trying to figure out the best way to handle screen clicks on moving objects onscreen and right now Im drawing everything in a canvas which inturn is drawn to a view but I cant make individual bitmaps representing objects clickable.
So before I throw out a lot of work already and try for it does anyone know if its possible to have dynamically moving objects within a view that can independently handle screen clicks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
OnTouchListener
添加到您的视图中(在画布上绘制所有对象的那个),并在onTouch(View v, MotionEvent event)
中获取事件的坐标:然后循环遍历您绘制和查看的对象如果这些坐标位于该对象的当前区域,如果所以,您知道它已被单击。
Add an
OnTouchListener
to your view (the one that that draws all your objects on the canvas), and in theonTouch(View v, MotionEvent event)
, get the coordinates of the event:Then loop through your objects that you draw and see if these coordinates are on that objects current area, if so, you know that it has been clicked.