Which Multi touch code should i use?
in
Android Processing
•
2 months ago
Seems either one I use I cause my game to freeze. Not all the time, but when i pull finger off the spots that activate particular actions rapidly and constantly it frequently causes the game to crash. I dont remember having a issue when it was single touch, but since ive been trying with multitouch it causes problems. What is the proper way of implementing multi touch does this code look flawed? Is it missing something? if my touches are within the designated spots do i need a else condition for when they are not?
Oh and is there a way of making it so it registers my touches even if I dont move my fingers? it seems to stop activating once both of my touches stop moving.
Also I use mouseX and mouseY to clear the initial splash screen. Could that cause confusion? but the issue never arises that early in the game.
Please and thank you for any help in regards to this.
void setup(){
//within setup i have the touches array
xTouch = new float[10];
yTouch = new float[10];
}
public boolean surfaceTouchEvent(MotionEvent event){
final int action = event.getAction();
TouchEvents = event.getPointerCount();
for (int i = 0; i<TouchEvents; i++){
int ID = event.getPointerId(i);
switch(action){
case MotionEvent.ACTION_DOWN:{
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
//else thrusters = false;
}
case MotionEvent.ACTION_MOVE:{
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
}
}
}return super.surfaceTouchEvent(event);}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////OR /////////////////////////////////////////////////
public boolean surfaceTouchEvent(MotionEvent event){
TouchEvents = event.getPointerCount();
for (int i = 0; i<TouchEvents; i++){
int ID = event.getPointerId(i);
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}
else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
//else thrusters = false;
}*/
Oh and is there a way of making it so it registers my touches even if I dont move my fingers? it seems to stop activating once both of my touches stop moving.
Also I use mouseX and mouseY to clear the initial splash screen. Could that cause confusion? but the issue never arises that early in the game.
Please and thank you for any help in regards to this.
void setup(){
//within setup i have the touches array
xTouch = new float[10];
yTouch = new float[10];
}
public boolean surfaceTouchEvent(MotionEvent event){
final int action = event.getAction();
TouchEvents = event.getPointerCount();
for (int i = 0; i<TouchEvents; i++){
int ID = event.getPointerId(i);
switch(action){
case MotionEvent.ACTION_DOWN:{
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
//else thrusters = false;
}
case MotionEvent.ACTION_MOVE:{
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
}
}
}return super.surfaceTouchEvent(event);}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////OR /////////////////////////////////////////////////
public boolean surfaceTouchEvent(MotionEvent event){
TouchEvents = event.getPointerCount();
for (int i = 0; i<TouchEvents; i++){
int ID = event.getPointerId(i);
xTouch[ID] = event.getX(i);
yTouch[ID] = event.getY(i);
if (xTouch[ID] >= 50 && xTouch[ID] <= 250 && yTouch[ID] >= 521 && yTouch[ID] <= 721){
my_ship.shoot();
x_angle = atan2(yTouch[ID]-620, xTouch[ID]-100);
}
else if (xTouch[ID] >= 1050 && xTouch[ID] < width-50 && yTouch[ID] >= 521 && yTouch[ID] <= 721) my_ship.push();
//else thrusters = false;
}*/
1