本文介绍了Android的 - 检测复杂的拖动路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近进入的Andr​​oid编程,并希望使使用二维绘图画布一个简单的游戏。我已签出月球着陆器的例子,在一些手势读了,但它看起来像是否发生一个手势我只能探测。我期待做一个刷卡稍微复杂的检测:

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:

我想打一个简单的游戏,用户可以通过屏幕上的一个或多个对象拖动手指,我希望能够检测到,他们在他们的道路走过去的对象。他们可能会开始垂直,然后水平,然后垂直又往前走,使得在连续刷卡结束时,他们选择了4个元素。

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)是否有公开让这样一个刷卡的完整路径的功能的API?
2)因为我在Canvas绘图,我不认为我将能够访问之类的东西的onMouseOver在我的游戏项目。我将不得不代替检测,如果刷卡是我精灵的边界框之内。我在思考这个正确?

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!

推荐答案

我决定实施
公共布尔onTouchEvent(MotionEvent事件)
在处理我的code为我的比赛。相反,越来越完整路径,我做了检查,以查看用户每次在onTouchEvent火灾的图块。我previously认为这事件上一摸发射只有一次,但只要你沿着屏幕表面移动,即使你没有修饰它激发。

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.

这篇关于Android的 - 检测复杂的拖动路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 15:07