如何使用AndEngine-Box2D扩展拖动实体



使用AndEngine Physics Box2D,我试图在x轴上左右拖动一个物体。

到目前为止,这就是我所拥有的,它工作不正常,身体在y轴上向上移动,并且没有跟随指针(手指)

 int P2M = 32;
final Vector2 v2 = Vector2Pool.obtain(x / P2M, this.getY() / P2M);
body.setTransform(v2, 0); // if you want you can also set the rotation here
Vector2Pool.recycle(v2);

有人熟悉这样做吗?

您可能应该使用body.getPosition().y而不是this.getY(),但我不知道如何获得x?如果你使用pSceneTouchEvent.getX(),那么它可以正常工作

Vector2 localPoint = Vector2Pool.obtain((pTouchAreaLocalX/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, (pTouchAreaLocalY/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
body.setTransform(body.getWorldPoint(localPoint), 0);
Vector2Pool.recycle(localPoint);

最新更新