Game Development Reference
In-Depth Information
The class MultiTouchScreen receives the MotionEvent from the main activity and checks
each gesture to see if the XY coordinates of the finger fall within the bounds of the gesture.
If so, then the gesture is executed. You can get the number of pointers from the MotionEvent
by calling
int count = e.getPointerCount();
Then, the coordinates for each pointer can be obtained by looping through the number of
pointers and extracting their XY coordinates, like so:
Point[] points = new Point[count];
// for each finger extract coords
for (int i = 0; i < points.length; i++) {
points[i] = new Point((int) e.getX(i), (int) e.getY(i));
}
Finally, you can check whether the pointer falls within the gesture bounds by looping through
each gesture and checking if each pointer XY coordinates falls within the gesture bounding
rectangle.
for (MultiTouchGesture g : mGestures) {
// for each finger (pointer)
for (int j = 0; j < count; j++) {
if (g.bounds.contains(points[j].x, points[j].y)) {
g.execute(action, points[j]);
}
}
}
TestActivity
The last thing you need is an activity that will initialize the multi-touch screen and the gesture
bounds, and listen for touch events (see Listing 2-10).
Listing 2-10. TestActivity for the MultiTouchScreen Class
public class TestActivity extends Activity {
MultiTouchScreen mtScreen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
 
Search WWH ::




Custom Search