0
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
float r = 70;
float centerLx = (float) (screenWidth*.3425);
float centerLy = (float) (screenHeight*.4958);
float centerRx = (float) (screenWidth*.6538);
float centerRy = (float) (screenHeight*.4917);
float dx = 0;
float dy = 0;
float theta;
float c;
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
int pid = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
int fingerid = event.getPointerId(pid);
int x = (int) event.getX(pid);
int y = (int) event.getY(pid);
c = FloatMath.sqrt(dx*dx + dy*dy);
theta = (float) Math.atan(Math.abs(dy/dx));
switch (actionCode) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
//if touching down on left stick, set leftstick ID to this fingerid.
if(x < screenWidth/2 && c<r*.8) {
lsId = fingerid;
dx = x-centerLx;
dy = y-centerLy;
touchingLs = true;
}
else if(x > screenWidth/2 && c<r*.8) {
rsId = fingerid;
dx = x-centerRx;
dy = y-centerRy;
touchingRs = true;
}
break;
case MotionEvent.ACTION_MOVE:
if (touchingLs && fingerid == lsId) {
dx = x - centerLx;
dy = y - centerLy;
}else if (touchingRs && fingerid == rsId) {
dx = x - centerRx;
dy = y - centerRy;
}
c = FloatMath.sqrt(dx*dx + dy*dy);
theta = (float) Math.atan(Math.abs(dy/dx));
//if touching outside left radius and moving left stick
if(c >= r && touchingLs && fingerid == lsId) {
if(dx>0 && dy<0) { //top right quadrant
lsX = r * FloatMath.cos(theta);
lsY = -(r * FloatMath.sin(theta));
Log.i("message", "top right");
}
if(dx<0 && dy<0) { //top left quadrant
lsX = -(r * FloatMath.cos(theta));
lsY = -(r * FloatMath.sin(theta));
Log.i("message", "top left");
}
if(dx<0 && dy>0) { //bottom left quadrant
lsX = -(r * FloatMath.cos(theta));
lsY = r * FloatMath.sin(theta);
Log.i("message", "bottom left");
}
else if(dx > 0 && dy > 0){ //bottom right quadrant
lsX = r * FloatMath.cos(theta);
lsY = r * FloatMath.sin(theta);
Log.i("message", "bottom right");
}
}
if(c >= r && touchingRs && fingerid == rsId) {
if(dx>0 && dy<0) { //top right quadrant
rsX = r * FloatMath.cos(theta);
rsY = -(r * FloatMath.sin(theta));
Log.i("message", "top right");
}
if(dx<0 && dy<0) { //top left quadrant
rsX = -(r * FloatMath.cos(theta));
rsY = -(r * FloatMath.sin(theta));
Log.i("message", "top left");
}
if(dx<0 && dy>0) { //bottom left quadrant
rsX = -(r * FloatMath.cos(theta));
rsY = r * FloatMath.sin(theta);
Log.i("message", "bottom left");
}
else if(dx > 0 && dy > 0) {
rsX = r * FloatMath.cos(theta);
rsY = r * FloatMath.sin(theta);
Log.i("message", "bottom right");
}
}
else {
if(c < r && touchingLs && fingerid == lsId) {
lsX = dx;
lsY = dy;
}
if(c < r && touchingRs && fingerid == rsId){
rsX = dx;
rsY = dy;
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
if (fingerid == lsId) {
lsId = -1;
lsX = 0;
lsY = 0;
touchingLs = false;
} else if (fingerid == rsId) {
rsId = -1;
rsX = 0;
rsY = 0;
touchingRs = false;
}
break;
}
return true;
}
에서 왼쪽 조이스틱 오른쪽 조이스틱있다 할 수 없습니다. 지금은 한 번에 하나만 움직입니다. 누군가가 올바른 길로 나를 설 수 있다면, 나는이 문제에 대해 악몽을 꾸며왔다.안드로이드는 독립적으로 이동하는 두 개의 가상 조이스틱을 얻을 수 있지만, 동시에