Ok so ive been programming with android for a couple of weeks now but im having so much trouble with the multitouch, ive tried googleing it and everything but i cant find any clear documentation or tutorials
basicly heres my code what im trying to do is have a joystick on the left side of the screen and a button on the right which i have already done.
the button and joystick work fine aslong as im not touching them both at the same time but this is what i need for my game
i have also tried action pointers but i dont think im using them right
any help would be awesome thanks
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int action = event.getAction() & MotionEvent.ACTION_MASK;
switch (action) {
case MotionEvent.ACTION_DOWN:
float tx = event.getX();
float ty = event.getY();
if (tx > (joystick.getWidth() / 3) * 2
&& tx < (joystick.getWidth() / 3) * 3
&& ty > (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)
&& ty < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3) * 2) {
touch_right(tx, ty);
invalidate();
}
if (tx > (joystick.getWidth() / 3)
&& tx < (joystick.getWidth() / 3) * 2
&& ty > (getHeight() - joystick.getHeight())
&& ty < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)) {
touch_forward(tx, ty);
invalidate();
}
if (tx > (joystick.getWidth() - joystick.getWidth())
&& tx < (joystick.getWidth() / 3)
&& ty > (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)
&& ty < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3) * 2) {
touch_left(tx, ty);
invalidate();
}
if (tx > (joystick.getWidth() / 3)
&& tx < (joystick.getWidth() / 3) * 2
&& ty > ((getHeight() - joystick.getHeight()) + (joystick
.getHeight() / 3) * 2)
&& ty < (getHeight() - joystick.getHeight())
+ (joystick.getHeight())) {
touch_down(tx, ty);
invalidate();
}
if (tx > getWidth() - button.getWidth() - (button.getWidth() / 4)
&& ty > getHeight() - button.getHeight()
- (button.getHeight() / 4)) {
yes = true;
}
break;
case MotionEvent.ACTION_MOVE:
float txm = event.getX();
float tym = event.getY();
if (txm > (joystick.getWidth() / 3) * 2
&& txm < (joystick.getWidth() / 3) * 3
&& tym > (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)
&& tym < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3) * 2) {
touch_right(txm, tym);
left = false;
invalidate();
}
if (txm > (joystick.getWidth() / 3)
&& txm < (joystick.getWidth() / 3) * 2
&& tym > (getHeight() - joystick.getHeight())
&& tym < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)) {
touch_forward(txm, tym);
right = false;
down = false;
left = false;
invalidate();
}
if (txm > (joystick.getWidth() - joystick.getWidth())
&& txm < (joystick.getWidth() / 3)
&& tym > (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3)
&& tym < (getHeight() - joystick.getHeight())
+ (joystick.getHeight() / 3) * 2) {
touch_left(txm, tym);
forward = false;
right = false;
down = false;
invalidate();
}
if (txm > (joystick.getWidth() / 3)
&& txm < (joystick.getWidth() / 3) * 2
&& tym > ((getHeight() - joystick.getHeight()) + (joystick
.getHeight() / 3) * 2)
&& tym < (getHeight() - joystick.getHeight())
+ (joystick.getHeight())) {
touch_down(txm, tym);
forward = false;
right = false;
left = false;
invalidate();
} else {
}
break;
case MotionEvent.ACTION_UP: {
touch_up();
invalidate();
yes = false;
break;
}
}
int action2 = event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK;
switch(action2){
case MotionEvent.ACTION_POINTER_1_DOWN:{
float txmp = event.getX(1);
float tymp = event.getY(1);
if (txmp > getWidth() - button.getWidth() - (button.getWidth() / 4)
&& tymp > getHeight() - button.getHeight()
- (button.getHeight() / 4)) {
yes = true;
}
break;
}
case MotionEvent.ACTION_POINTER_2_DOWN:{
float txmp = event.getX(1);
float tymp = event.getY(1);
if (txmp > getWidth() - button.getWidth() - (button.getWidth() / 4)
&& tymp > getHeight() - button.getHeight()
- (button.getHeight() / 4)) {
yes = true;
}
break;
}
case MotionEvent.ACTION_POINTER_3_DOWN:{
int txmpe = event.getPointerId(action2);
int tympe = event.getPointerId(action2);
float txmp = event.getX(txmpe);
float tymp = event.getY(tympe);
if (txmp > getWidth() - button.getWidth() - (button.getWidth() / 4)
&& tymp > getHeight() - button.getHeight()
- (button.getHeight() / 4)) {
yes = true;
}
break;
}
}
return true;
}
private void touch_up() {
left = false;
right = false;
jump_true = 0 ;
jump_is = true;
forward = false;
down = false;
}