@Override
public boolean onTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
switch (state)
{
case Ready:
{
state = GameState.Running;
break;
}
case GameOver:
{
state=GameState.Ready;
plane.getBombs().clear();
soldier.setAlive(true);
break;
}
case Paused:
{
state = GameState.Running;
break;
}
case Running:
{
if (event.getX() < screenWidth/2)
{
soldier.moveLeft();
soldier.setMovingLeft(true);
}
else if (event.getX() > screenWidth/2 )
{
soldier.moveRight();
soldier.setMovingRight(true);
}
}
break;
default:
break;
}
}
else if (event.getAction() == MotionEvent.ACTION_UP)
{
if (event.getX() < screenWidth/2)
{
soldier.stopLeft();
}
if (event.getX() > screenWidth/2)
{
soldier.stopRight();
}
}
return true;
}
如果我用一根手指握住并触摸右侧球员移动很好但触摸右侧并且我向左触摸并释放球员向右移动直到我触摸右侧
答案 0 :(得分:0)
尝试更改:
public void moveLeft() { speedX = -moveSpeed; }
到:
public void moveLeft() { speedX -= moveSpeed; }