How to code for multitouch

后端 未结 2 1987
臣服心动
臣服心动 2020-12-28 10:28

So I\'m developing an application that must handle multitouch. Basically I want single touch for rotating ( this is no problem ). And multitouch for scrolling.

I h

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 11:06

    You can solve this with simple math, although there may be a better way already built in.

    Just create an object that holds the position of each finger when the .ACTION_POINTER_X_UP event fires and a boolean object that holds which type of touchmode you last used.

    case MotionEvent.ACTION_POINTER_1_UP:
            camera.onTouchDown( xEvent[ 1 ], yEvent[ 1 ] );
            boolean usedMultiTouch = true;
            int x = event.getX(1);
            int y = event.getY(1);
            return true;
    

    Next your ACTION_MOVE (inside the case=1) statement will fire as the user moves their finger as they went from multi to single touch.

    Now, depending on what you want to do, you can either ignore the single move (the boolean is your check) until the .ACTION_UP event fires and you set the boolean back to false

    or

    you call a method that does some math based on the saved location values and the finger that is still on the screen. The math should be pretty easy, but I don't know what you actually want to do.

提交回复
热议问题