所以我想建立一个游戏屏幕上的操纵杆是移动屏幕上的位图。 但是,当我握住操纵杆倒在任何方向,并保持它在那里,该位将停止移动为好。 它只有当我移动操纵杆做位图的举动。 基本上,我希望能够按住操纵杆发言权左侧位置,并有位向左移动,直到我放手。 一切都在代码工作人。 有什么建议?
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
_dragging = true;
else if (event.getAction() == MotionEvent.ACTION_UP)
_dragging = false;
_touchingPoint = new Point();
if (_dragging) {
// get the pos
int x = (int) event.getX();
int y = (int) event.getY();
_touchingPoint.x = x;
_touchingPoint.y = y;
double a = _touchingPoint.x - initx;
double b = _touchingPoint.y - inity;
controllerDistance = Math.sqrt((a * a) + (b * b));
if (controllerDistance > 75) {
a = (a / controllerDistance) * 75;
b = (b / controllerDistance) * 75;
_touchingPoint.x = (int) a + initx;
_touchingPoint.y = (int) b + inity;
}
bitmapPoint.x += a * .05;
bitmapPoint.y += b * .05;
} else if (!_dragging) {
// Snap back to center when the joystick is released
_touchingPoint.x = initx;
_touchingPoint.y = inity;
}
}