onTouchEvent MotionEvent.ACTION_UP registering to slowly

42 Views Asked by At

I have a 2D car hotlaping game, where pressing and holding the press of the left side of the screen turns left, same for the right side and when letting go of touching the screen the car goes straight. The problem is, when for example pressing the left side of the screen and after that quickly letting go of touching then touching the right side, the car still turns left. It seems like the onTouchEvent is too slow to register the MotionEvent.ACTION_UP/DOWN.

public boolean onTouchEvent(MotionEvent event) {
        switch(event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                if (event.getX() < screenX / 2) {
                    player.isGoingRight = true;
                    player.touch = true;
                }
                if (event.getX() > screenX / 2) {
                    player.isGoingLeft = true;
                    player.touch = true;
                }
                break;
            case MotionEvent.ACTION_UP:
                player.isGoingRight = false;
                player.isGoingLeft = false;
                player.touch = false;
                break;
        }

        return true;
    } 
0

There are 0 best solutions below