Odd Android touch event problem

Posted by user22241 on Game Development See other posts from Game Development or by user22241
Published on 2013-05-31T00:42:54Z Indexed on 2013/10/28 22:15 UTC
Read the original article Hit count: 345

Filed under:
|
|
|
|

Overview

When testing my game I came across a bizarre problem with my touch controls.

Note this isn't related to multi-touch as I completely removed my ACTION_POINTER_UP and ACTION_POINTER_DOWN along with my ACTION_MOVE code. So I'm simply working with ACTION_UP and ACTION_DOWN now and still get the problem.

The problem

I have a left and right button on the left of the screen and a jump button on the right. Everything works as it should but if I touch a large area of my hand (the fleshy part at the base of the thumb for instance) onto the screen, then release it and then press one of my arrows, the sprite moves in that direction for a few seconds, and then ACTION_UP is mysteriously triggered. The sprite stops and then if I release my finger and re-apply it to an arrow, the same thing happens. This goes on and on and eventually (randomly??) stops and everything work OK again.

Test device & OS

Google Nexus 10 Tablet running Jellybean 4.2.2

Code

        //Action upon which to switch
        actionMask = event.getActionMasked();
        //Pointer Index of the currently touching pointer
        pointerIndex = event.getActionIndex();
        //Number of pointers (for multi-touch)
        pointerCount = event.getPointerCount();
        //ID of the pointer currently being processed (Multitouch)
        pointerID = event.getPointerId(pointerIndex);

        switch (actionMask){

        //Primary pointer down
        case MotionEvent.ACTION_DOWN: {

        //if pressing left button then set moving left
        if (isLeftPressed(event.getX(), event.getY())){
                    renderer.setSpriteLeft();
                }

        //if pressing right button then set moving right
        else if (isRightPressed(event.getX(), event.getY())){
                    renderer.setSpriteRight();
                }

        //if pressing jump button then set sprite jumping
        else if (isJumpPressed(event.getX(),event.getY())){
                    renderer.setSpriteState('j', true);
                }

        break;

        }//End of case

        //Primary pointer up
        case MotionEvent.ACTION_UP:{

        //When finger leaves the screen, stop sprite's horizontal movement
            renderer.setSpriteStopped();
            break;
        }

© Game Development or respective owner

Related posts about android

Related posts about screen