0
\$\begingroup\$

Im trying to make make game which is intended to be played with the phone in landscape mode, and the player uses their thumbs to control the movement. The game controls look like this:

enter image description here

On the left there is a simple button to accelerate, and on the right a wheel to adjust the direction. Both work perfectly when used individually but they won't work both at the same time.

I would need to implement multitouch and accelerate/rotate depending on which side of the screen the finger is on, but I can't figure out how to do that detection.

Below is the onTouchEvent, how can i modify it to do what i want?

@Override
    public boolean onTouchEvent(MotionEvent event){

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (event.getX() < 300 && event.getY() > 250) {
                    btnPress = true;
                }
                break;
            case MotionEvent.ACTION_MOVE:
                x = (int) event.getX(); //this is used by the direction wheel
                y = (int) event.getY();
                break;
            case MotionEvent.ACTION_UP:
                btnPress = false;
                break;

        }
        return true;
    }
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Presumably, you read the documentation and realized that the action for additional pointers was different, and that you had to keep track of the pointer ids to figure out what is going on? \$\endgroup\$
    – Vaillancourt
    Commented May 7, 2019 at 20:41

1 Answer 1

0
\$\begingroup\$

You need to separate the two control areas not just for ACTION_DOWN but also for ACTION_MOVE and ACTION_UP.

Currently, you only check the 0..320, 0..250 area in the ACTION_DOWN.

\$\endgroup\$
1
  • \$\begingroup\$ I just tried this but what happens is that if I have my finger on the left button, the wheel is unresponsive. And if Im using the wheel, the button can't be pressed \$\endgroup\$
    – tacofisher
    Commented Oct 10, 2017 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .