ポインタのリストを取得しようとしていますが、画面上のピクセル位置とその位置が画面上にあるので、デスクトップゲームをアンドロイドに移植できます。そうするために、私はこのonTouchハンドラを書いています。Androidマルチタッチ - TouchMoveイベントのIllegalArgumentException
private boolean onTouch(View v, MotionEvent e)
{
final int action = e.getActionMasked();
switch (action)
{
case MotionEvent.ACTION_DOWN:
surfaceView.queueEvent(() -> postTouchEvent(FINGER_0, true, e.getX(), e.getY()));
break;
case MotionEvent.ACTION_UP:
surfaceView.queueEvent(() -> postTouchEvent(FINGER_0, false, e.getX(), e.getY()));
break;
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_UP:
{
final int index = e.getActionIndex();
final int finger = index + 1;
if (finger < FINGER_1 || finger > FINGER_9)
break;
final boolean isDown = action == MotionEvent.ACTION_POINTER_DOWN;
surfaceView.queueEvent(() -> postTouchEvent(finger, isDown, e.getX(), e.getY()));
}
break;
case MotionEvent.ACTION_MOVE:
for (int i = 0; i < e.getPointerCount(); i++)
{
final int finger = i + 1;
if (finger < FINGER_0 || finger > FINGER_9)
break;
surfaceView.queueEvent(() ->
postTouchEvent(finger, true, e.getX(finger - 1), e.getY(finger - 1)));
}
for (int i = e.getPointerCount(); i < FINGER_9; i++)
{
final int finger = i + 1;
surfaceView.queueEvent(() -> postTouchEvent(finger, false, 0, 0));
}
break;
}
return true;
}
問題がACTION_MOVE
イベントであるしかし、私は私のインデックスidをアクセスするためのIllegalArgumentException
を取得しています。これは、一度に3つ以上の指を画面上でタップした場合にのみ発生しますが、それでも問題になります。例外は次のとおりです。
FATAL EXCEPTION: GLThread 61026
Process: com.shc.silenceengine.tests.android, PID: 23077
java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:2014)
at com.shc.silenceengine.backend.android.AndroidInputDevice.lambda$onTouch$14(AndroidInputDevice.java:228)
at com.shc.silenceengine.backend.android.AndroidInputDevice.access$lambda$6(AndroidInputDevice.java)
at com.shc.silenceengine.backend.android.AndroidInputDevice$$Lambda$7.run(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
私は私だけe.getPointerCount()
までのループのためにやっているので、私はエラーを取得していますなぜコードの出入り指数の見込みがないかわかりません。
私はポインタIDを追跡したくありません。私はポインタの生のリストがほしいと思っています。これらのイベントはエンジンリストの次のフレームになります。
問題がどこにあるのですか?
まさに!これを指摘してくれてありがとう。 –