I've spent countless hours on reading tutorials and looking at every question related to multiTouch from here and Stackoverflow. But I just cannot figure out how to do this correctly. I use a loop to get my pointerId, I dont see alot of people doing this but its the only way I've managed to get it somewhat working.
I have two joysticks on my screen, one for moving and one for controlling my sprites rotation and the angle he shoots, like in Monster Shooter. Both these work fine.
My problem is that when I Move my sprite at the same time as Im shooting, my touchingPoint for my movement is set to the touchingPoint of my shooting, since the x and y is higher on the touchingPoint of my shooting (moving-stick on left side of screen, shooting-stick on right side), my sprite speeds up, this creates an unwanted change in speed for my sprite.
I will post my entire onTouch method here with some variable-changes to make it more understandable. Since I do not know where Im going wrong.
public void update(MotionEvent event) {
if (event == null && lastEvent == null) {
return;
} else if (event == null && lastEvent != null) {
event = lastEvent;
} else {
lastEvent = event;
}
int pointerCount = event.getPointerCount();
for (int i = 0; i < pointerCount; i++)
{
int x = (int) event.getX(i);
int y = (int) event.getY(i);
int id = event.getPointerId(i);
int action = event.getActionMasked();
int actionIndex = event.getActionIndex();
String actionString;
switch (action)
{
case MotionEvent.ACTION_DOWN:
actionString = "DOWN";
break;
case MotionEvent.ACTION_UP:
shooting=false; // when shooting is true, it shoots
dragging=false; // when dragging is true, it moves
actionString = "UP";
break;
case MotionEvent.ACTION_POINTER_DOWN:
actionString = "PNTR DOWN";
break;
case MotionEvent.ACTION_POINTER_UP:
shooting=false;
dragging=false;
actionString = "PNTR UP";
break;
case MotionEvent.ACTION_CANCEL:
shooting=false;
dragging=false;
actionString = "CANCEL";
break;
case MotionEvent.ACTION_MOVE:
try{
if((int) event.getX(id) > 0 && (int) event.getX(id) < touchingBox
&& (int) event.getY(id) > touchingBox && (int) event.getY(id) < view.getHeight()){
movingPoint.x = (int) event.getX(id);
movingPoint.y = (int) event.getY(id);
dragging = true;
}
else if((int) event.getX(id) > touchingBox && (int) event.getX(id) < view.getWidth()
&& (int) event.getY(id) > touchingBox && (int) event.getY(id) < view.getHeight()){
shootingPoint.x = (int) event.getX(id);
shootingPoint.y = (int) event.getY(id);
shooting=true;
}else{
shooting=false;
dragging=false;
}
}catch(Exception e){
}
actionString = "MOVE";
break;
default:
actionString = "";
}
Wouldnt post this much code if I wasnt at an absolute loss of what I'm doing wrong. I simply can not get a good understanding of how multiTouching works.
basicly movingPoint changes for both my first and second finger. I bind it to a box, but aslong as I hold one finger within this box, it changes its value based on where my second finger touches. It moves in the right direction and nothing gives an error, the problem is the speed-change, its almost like it adds up the two touchingPoints.