Here's the basics you need to know:
- setup an event handler to handle your ontouch events
- touch events have different actions: ACTION_DOWN, ACTION_UP, etc. are used for the first touch event registered. ACTION_POINTER_DOWN, ACTION_POINTER_UP are used for the second touch event. As far as I know Android only supports 2 touch events.
- to use the second event, you must combine the event.getAction() and MotionEvent.ACTION_MASK by anding them as seen below.
First you need to catch your action in your touch event and store it as an int:
public class GameEvent implements OnTouchListener{
public boolean onTouch(View v, MotionEvent event) {
actionCode = event.getAction() & MotionEvent.ACTION_MASK;//this combines single and multitouch
}
}
Then test to see what the event action was:
if(actionCode == MotionEvent.ACTION_DOWN){
}else if(actionCode == MotionEvent.ACTION_POINTER_DOWN )...
from here you can get the X&Y coordinates of each touch, the pressure, and more.
No comments:
Post a Comment