У меня возникли проблемы с реализацией multi-touch, который я искал какое-то время. текущая реализация работает, но прерывает другой ввод. этот код является частью моего контроллера ввода, который обрабатывает/выводит области ввода. событие Motion передается через эту функцию из OnTouchEvent(), . Я прочитал, что вы должны использовать идентификатор указателя для правильного отслеживания, но каждый раз, когда я пытаюсь реализовать его, указатель указателя выходит за пределы диапазона. я мог бы реально использовать некоторую помощьнадлежащим образом обрабатывать мультитач-событие android
public void handleInput(MotionEvent motionEvent,LevelManager l, SoundManager sound, Viewport vp){
int pointerCount = motionEvent.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
int x = (int) motionEvent.getX(i);
int y = (int) motionEvent.getY(i);
if(l.isPlaying()) {
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
if (right.contains(x, y)) {
l.player.setPressingRight(true);
l.player.setPressingLeft(false);
} else if (left.contains(x, y)) {
l.player.setPressingLeft(true);
l.player.setPressingRight(false);
} else if (jump.contains(x, y)) {
l.player.startJump(sound);
} else if (shoot.contains(x, y)) {
if(l.player.pullTrigger()){
sound.playSound("shoot");
}
} else if (pause.contains(x, y)) {
l.switchPlayingStatus();
}
break;
case MotionEvent.ACTION_UP:
if (right.contains(x, y)) {
l.player.setPressingRight(false);
} else if (left.contains(x, y)) {
l.player.setPressingLeft(false);
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
if (right.contains(x, y)) {
l.player.setPressingRight(true);
l.player.setPressingLeft(false);
} else if (left.contains(x, y)) {
l.player.setPressingLeft(true);
l.player.setPressingRight(false);
} else if (jump.contains(x, y)) {
l.player.startJump(sound);
} else if (shoot.contains(x, y)) {
if(l.player.pullTrigger()){
sound.playSound("shoot");
}
} else if (pause.contains(x, y)) {
l.switchPlayingStatus();
}
break;
case MotionEvent.ACTION_POINTER_UP:
if (right.contains(x, y)) {
l.player.setPressingRight(false);
} else if (left.contains(x, y)) {
l.player.setPressingLeft(false);
} else if (shoot.contains(x, y)) {
//Handle shooting here
} else if (jump.contains(x, y)) {
//Handle more jumping stuff here later
}
break;
}
}else {// Not playing
//Move the viewport around to explore the map
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
if (right.contains(x, y)) {
vp.moveViewportRight(l.mapWidth);
} else if (left.contains(x, y)) {
vp.moveViewportLeft();
} else if (jump.contains(x, y)) {
vp.moveViewportUp();
} else if (shoot.contains(x, y)) {
vp.moveViewportDown(l.mapHeight);
} else if (pause.contains(x, y)) {
l.switchPlayingStatus();
}
break;
}
}
}
}
я была верна, то цикл теперь избыточно. мне кажется странным, но я пойду с ним, – naahn