Android - 检测复杂拖动的路径

发布于 2024-09-26 03:57:49 字数 371 浏览 3 评论 0原文

我最近开始涉足 Android 编程,想要使用 2D 画布绘图制作一个简单的游戏。我已经查看了月球着陆器示例并阅读了一些手势,但看起来我只能检测手势是否发生。我希望在滑动时进行更复杂的检测:

我想制作一个简单的游戏,用户可以将手指拖动到屏幕上的一个或多个对象上,并且我希望能够检测到他们经过的对象在他们的道路上。他们可能会开始垂直移动,然后水平移动,然后再次垂直移动,这样在连续滑动结束时他们就选择了 4 个元素。

1)是否有 API 公开了获取像这样的滑动完整路径的功能? 2)由于我在画布上绘图,我认为我无法访问游戏中项目的“onMouseOver”之类的东西。我将不得不检测滑动是否在我的精灵的边界框中。我的想法正确吗?

如果我忽略了一个明显的帖子,我深表歉意。先感谢您!

I am recently getting into Android programming and want to make a simple game using 2D canvas drawing. I have checked out the Lunar Lander example and read up on some gestures, but it looks like I can only detect if a gesture occurred. I am looking to do a little more complicated detection on a swipe:

I want to make a simple game where a user can drag their finger through one or more objects on the screen and I want to be able to detect the objects that they went over in their path. They may start going vertically, then horizontally, then vertically again, such that at the end of a contiguous swipe they have selected 4 elements.

1) Are there APIs that expose the functionality of getting the full path of a swipe like this?
2) Since I am drawing on a Canvas, I don't think I will be able to access things like "onMouseOver" for the items in my game. I will have to instead detect if the swipe was within the bounding box of my sprites. Am I thinking about this correctly?

If I have overlooked an obvious post, I apologize. Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃酥萝莉 2024-10-03 03:57:49

我决定实施
public boolean onTouchEvent(MotionEvent 事件)
我的游戏代码中的处理程序。我没有获取完整路径,而是在每次 onTouchEvent 触发时检查用户位于哪个图块上。我以前认为该事件仅在第一次触摸时触发一次,但只要您沿着屏幕表面移动,即使您没有进行修饰,它也会触发。

I decided to implement the
public boolean onTouchEvent(MotionEvent event)
handler in my code for my game. Instead of getting the full path, I do a check to see which tile the user is over each time the onTouchEvent fires. I previously thought this event fired only once on the first touch, but it fires as long as you are moving along the surface of the screen, even if you haven't retouched.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文