我正在尝试将身体从其初始位置移动到 onTouchEvent x 和 y。问题是身体正在朝着错误的方向移动。有人能告诉我我的错误在哪里吗?
到目前为止,这是我的代码:
public boolean onPlayerTouchEvent(final Scene pScene,
final TouchEvent pSceneTouchEvent) {
final float pValueX = pSceneTouchEvent.getX();
final float pValueY = pSceneTouchEvent.getY();
final float rotation = (float) Math.atan2(pValueX, pValueY);
final float xComp = (float) Math.sin(rotation);
final float yComp = (float) Math.cos(rotation);
if (pSceneTouchEvent.isActionDown()) {
this.mPlayerBody.setLinearVelocity(new Vector2(xComp, yComp));
} else if (pSceneTouchEvent.isActionMove()) {
} else if (pSceneTouchEvent.isActionUp()) {
this.mPlayerBody.setLinearVelocity(new Vector2(0, 0));
}
return true;
}