そこで、画面上でビットマップを移動する画面上のジョイスティックを使用してゲームを作成しようとしています。ただし、ジョイスティックを任意の方向に押したままにしておくと、ビットマップの移動も停止します。ジョイスティックを動かしているときだけ、ビットマップが動きます。基本的には、ジョイスティックを左の位置に押したままにして、手放すまでビットマップを左に移動できるようにしたいです。コード内の他のすべてが機能します。助言がありますか?
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;
}
}