pointerIndex out of range Android multitouch

前端 未结 6 1476
天涯浪人
天涯浪人 2020-12-02 18:24

I have a touch event exception that is causing my game to crash on tablets (or more specifically, honeycomb)... My game works fine on my phone and I haven\'t heard of this h

6条回答
  •  生来不讨喜
    2020-12-02 18:57

    The original posting is using the pointer id when the getX and getY use the pointer index.

    It appears to work when you use the ID for a single touch because the id and the index are both 0. It will mess up if you use a multi-touch because the indexes can change.

    Example:

    Touch 1 Down.
    Touch 1 State Index=0. ID=0

    Touch 2 Down.
    Touch 1 State Index=0. ID=0
    Touch 2 State Index=1. ID=1

    Touch 1 Release.
    Touch 2 State Index=0. ID=1

    Try the following code:

    final int action = e.getAction();       
    final int pointerIndex =(action & MotionEvent.ACTION_POINTER_INDEX_MASK) 
                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;      
    float x = event.getX(pointerIndex);
    float y = event.getY(pointerIndex);
    

提交回复
热议问题