android multitouch problem
- by Max
Im aware that there a a couple of posts on this matter, but Ive tried all of them and none of them gets rid of my problem.
Im starting to get close to the end of my game so I bought a cabel to try it on a real phone, and as I expected my multitouch dosnt work. I use 2 joysticks, one to move my character and one to change his direction so he can shoot while walking backwards etc.
my local variable:
public void update(MotionEvent event) {
if (event == null && lastEvent == null) {
return;
} else if (event == null && lastEvent != null) {
event = lastEvent;
} else {
lastEvent = event;
}
int index = event.getActionIndex();
int pointerId = event.getPointerId(index);
statement for left Joystick:
if (pointerId == 0 && event.getAction() == MotionEvent.ACTION_DOWN && (int) event.getX() > steeringxMesh - 50 && (int) event.getX() < steeringxMesh + 50 && (int) event.getY() > yMesh - 50 && (int) event.getY() < yMesh + 50) {
dragging = true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
dragging = false;
}
if (dragging) { //code for moving my character
statement for my right joystick:
if (pointerId == 1 && event.getAction() == MotionEvent.ACTION_DOWN && (int) event.getX() > shootingxMesh - 50 && (int) event.getX() < shootingxMesh + 50 && (int) event.getY() > yMesh - 50 && (int) event.getY() < yMesh + 50) {
shooting = true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
shooting = false;
}
if (shooting) {
// code for aiming
}
This class is my main-Views onTouchListener and is called in a update-method that gets called in my game-loop, so its called every frame.
Im really at a loss here, I've done a couple of tutorials and Ive tried all relevant solutions to similar posts.
Can post entire Class if necessary but I think this is all the relevant code. Just hope someone can make some sence out of this.