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.

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;
        }
share|improve this question
    
I still have this problem but I think it might be a bug in Jellybean (or a problem with the Google Nexus 10 hardware) - I downloaded a couple of games from the Playstore and succeeded in easily re-creating the problem. Not sure if others are having the same issue with either this OS version or Device? Gald it's not my code! But it's still annoying, I hope it's fixed in any new update...... :-) –  user22241 Jun 17 '13 at 16:42
add comment

1 Answer 1

I am not sure if I am understanding this correct, but it seems to me like you answered your own question.

I touch a large area of my hand onto the screen, then release it

Well you touched the screen and release it there are two calls to MotionEvent one with event.ACTION_DOWN and one with event.ACTION_UP

then press one of my arrows

Again a call to MotionEvent ACTION_DOWN, and most importantly it moves your sprite the way it is intended. ACTION_DOWN triggers your:

case MotionEvent.ACTION_DOWN: {
    if (isLeftPressed(event.getX(), event.getY())){
                renderer.setSpriteLeft();
            } ...

if I release my finger

and then once you lift your finger that triggers the ACTION_UP.

case MotionEvent.ACTION_UP:{

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

and re-apply it to an arrow, the same thing happens

... rinse and repeat

No mystery. A person cannot both be pushing on the screen and not pushing on the screen.

Why do you think this should not be happening? Could it be an error within your

setSpriteLeft(); or setSpriteStopped();

http://developer.android.com/reference/android/view/MotionEvent.html

share|improve this answer
    
No, what should happen - press movement button, sprite moves, lift finger, sprite stops. This does happen, but if, before I do this, I touch a large area of the screen, then release it, then start to control my sprite........press finger down, sprite moves, then stops because ACTION_UP is triggered even though my finger is still pressed down. Just for reference for anyone having a similar issue, I have since updated to Kit Kat and the same thing happens, so either it's not been been fixed or (more likely) it's just an issue with the Nexus 10's screen –  user22241 Feb 28 at 0:24
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.