我的安卓游戏需要一些帮助。我想设置一个模拟棒 - 2个圆圈。 1可移动。当你握住较小的那个时,它会移动屏幕上的角色。
现在我正在使用DrawableImages来更改值,但这不太舒服:
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()){
case R.id.upButton:
gameEngine.moveUp();
return true;
case R.id.downButton:
gameEngine.moveDown();
return true;
case R.id.leftButton:
gameEngine.moveLeft();
return true;
case R.id.rightButton:
gameEngine.moveRight();
return true;
case R.id.down_left:
gameEngine.moveDownLeft();
return true;
case R.id.down_right:
gameEngine.moveDownRight();
return true;
case R.id.up_left:
gameEngine.moveUpLeft();
return true;
case R.id.up_right:
gameEngine.moveUpRight();
return true;
case R.id.button_attack:
paintGame.setAttack();
gameEngine.attack();
return true;
}
return false;
}
};
public void moveUp(){
charX -= 8;
}
public void moveDown(){
charX += 8;
}
public void moveRight(){
charY +=8;
}
public void moveLeft(){
charY -= 8;
}
public void moveDownLeft(){
charX += 4;
charY -= 4;
}
public void moveUpLeft(){
charX -= 4;
charY -= 4;
}
public void moveDownRight(){
charX += 4;
charY +=4;
}
public void moveUpRight(){
charX -= 4;
charY +=4;
}
我不知道我怎么能意识到这一点。我希望你能帮助我。
谢谢!