Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

OK, my multi-touch system was somewhat convoluted, but was working perfectly OK until I tried to run my game on my Nexus 10 which is running Jellybean.

Crashing all over the place! So I removed my whole multi-touch routine and am trying to start from scratch and to simplify it.

Basically, I have 3 buttons, left, right and jump. Left is left of screen, right is right of screen and jump is in the middle.

What I need is when the player presses left and that button held down and then they press right, for the latter touch to override, so the right touch registers and the character moves from left to right. If he then releases one of the buttons the character moves in the direction of the button which remains pressed. Again, same with jump.

I can get my character moving left and right with single-touch but all day I've been trying to understand multi-touch and just can't get it.

I don't understand the whole pointer ID's and pointer Indexes and would be really grateful if someone could just explain and give an example of some code which would accomplish what I require. Just 2 buttons would do and I could go from there.

Many thanks!

edit

Here is some really basic code and the results I get from it:

public boolean onTouchEvent(MotionEvent event) {

int action = event.getAction() & MotionEvent.ACTION_MASK;
int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
int pointerId = event.getPointerId(pointerIndex);

        Log.v("multitouch","pointer ID "+pointerId);
            Log.v("multitouch","pointer Index "+pointerIndex);

    return true;

}
  • when I press the first finger down, ID and Index are both 0
  • when I press the second finger down, ID and Index are both 0
  • if second finger is released and the first one remains, the ID and Index are both 0
  • However, if the first finger is release and the second one remains then the Index is 0 but the ID is 1

I don't understand how this works and how I can use it to determine which fingers are on the screen at which time and would really be grateful if someone could throw some light on it for me - thanks!!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.