Monday, 27 May 2013

Android multitouch: How to detect movement on non-primary pointer / finger?

Android multitouch: How to detect movement on non-primary pointer / finger?

How does one go about detecting a secondary/non-primary finger moving?
There is:
ACTION_DOWN and ACTION_UP to detect a primary finger pressing the screen / leaving the screen
ACTION_POINTER_DOWN and ACTION_POINTER_UP for subsequent fingers pressing / leaving the screen
But there is no ACTION_POINTER_MOVE for monitoring and responding to subsequent fingers moving.
Also, if I log event.getActionIndex(); it always returns '0' regardless of how many fingers are touching the screen (I'm guessing because *ACTION_MOVE* is only interested in the primary finger). So how is it possible test the subsequent fingers?
Code
case MotionEvent.ACTION_MOVE:{ 
         int pointerId = event.getPointerId(pointerIndex); 

        //Finger slid to left button so set sprite left 
            if (event.getY(pointerIndex)>=renderer.leftButton("top") && event.getX(pointerIndex)<=renderer.leftButton("right")){ 
                renderer.setSpriteState('l', true); 
                renderer.setSpriteState('r', false); 

        } 

            //Finger slide to the right button so set sprite right 
            else     
                if (event.getY(pointerIndex)>=renderer.rightButton("top") && event.getX(pointerIndex)>renderer.rightButton("left") && event.getX(pointerIndex)<=renderer.rightButton("right")){ 
                    renderer.setSpriteState('l', false); 
                    renderer.setSpriteState('r', true); 

            } 
            break;

No comments:

Post a Comment