繁体   English   中英

如何使用AndEngine Box2D扩展拖动主体

[英]How to drag body using AndEngine Box2D extension

我试图使用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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM