Hello,
I’m working on a platfrom game for android and as in most platfrom games the player will need to use multi touch, for example moving right and jumping simultaneous.
This my code:
public boolean onTouch(MotionEvent e, int scaledX, int scaledY) {
int action = e.getAction() & MotionEvent.ACTION_MASK;
for (int i = 0; i < object.size(); i++) {
tempObject = object.get(i);
if (tempObject.getId() == ObjectId.Player) {
switch (action) {
case MotionEvent.ACTION_UP:
if (moveLeft.contains(scaledX, scaledY)) {
tempObject.setMovingLeft(false);
}
if (moveRight.contains(scaledX, scaledY)) {
tempObject.setMovingRight(false);
}
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_DOWN:
if (jump.contains(scaledX, scaledY)) {
if (tempObject.getVelY() == 0 && tempObject.isJumping() == false) {
tempObject.setVelY((float) -11.5);
tempObject.setJumping(true);
}
}
if (restart.contains(scaledX, scaledY)) {
restart();
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_MOVE:
if (moveLeft.contains(scaledX, scaledY)) {
tempObject.setMovingLeft(true);
tempObject.setMovingRight(false);
}
if (moveLeftExit.contains(scaledX, scaledY) && !moveLeft.contains(scaledX, scaledY)) {
tempObject.setMovingLeft(false);
}
if (moveRight.contains(scaledX, scaledY)) {
tempObject.setMovingRight(true);
tempObject.setMovingLeft(false);
}
if (moveRightExit.contains(scaledX, scaledY) && !moveRight.contains(scaledX, scaledY)) {
tempObject.setMovingRight(false);
}
break;
}
}
}
return true;
}
The problem is if I touch a rect while touching a different rect, the new touch wont react and the old on gets “stuck”.
Thanks