Revert "Revert "cmd/ebitenmobile: bug fix: multiple touches were not updated correctly on Android""

This reverts commit af4832b0ad.

Reason: As v2.3 will be released for another fix (#2252), let's include the fix for #2220

Updates #2220
This commit is contained in:
Hajime Hoshi 2022-08-18 19:07:14 +09:00
parent 071d96f16d
commit 9e4aa570cf
2 changed files with 7 additions and 2 deletions

View File

@ -419,11 +419,16 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
@Override
public boolean onTouchEvent(MotionEvent e) {
// getActionIndex returns a valid value only for the action whose index is the returned value of getActionIndex (#2220).
// See https://developer.android.com/reference/android/view/MotionEvent#getActionMasked().
// For other pointers, treat their actions as MotionEvent.ACTION_MOVE.
int touchIndex = e.getActionIndex();
for (int i = 0; i < e.getPointerCount(); i++) {
int id = e.getPointerId(i);
int x = (int)e.getX(i);
int y = (int)e.getY(i);
Ebitenmobileview.updateTouchesOnAndroid(e.getActionMasked(), id, (int)pxToDp(x), (int)pxToDp(y));
int action = (i == touchIndex) ? e.getActionMasked() : MotionEvent.ACTION_MOVE;
Ebitenmobileview.updateTouchesOnAndroid(action, id, (int)pxToDp(x), (int)pxToDp(y));
}
return true;
}

File diff suppressed because one or more lines are too long