Android - sophisticated drag and drop detection

I recently got into Android programming and want to make a simple game using a 2D canvas. I checked the Lunar Lander example and read some gestures, but it looks like I can only determine if the gesture has occurred. I want to make a slightly more sophisticated hit detection:

I want to create a simple game in which the user can drag a finger across one or more objects on the screen, and I want to be able to detect the objects that they moved in their path. They can start vertically, then horizontally, then vertically again, so that at the end of a continuous swipe they selected 4 elements.

1) Are there APIs that expose the functionality of getting the full path for a swipe? 2) Since I draw on canvas, I don’t think I can access things like “onMouseOver” for items in my game. Instead, I will have to find that the napkins were within the bounding box of my sprites. Am I thinking about it right?

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

+4
source share
1 answer

I decided to implement a public boolean onTouchEvent(MotionEvent event) handler in my code for my game. Instead of getting the full path, I check to see which tile the user will earn every time onTouchEvent fires. I previously thought that this event only fires once the first time it is touched, but it fires as long as you move across the surface of the screen, even if you haven't retouched.

+2
source

All Articles