[英]How to drag body using AndEngine Box2D extension
Using AndEngine Physics Box2D i am trying to drag a body from side to side on the x axis. 我试图使用AndEngine Physics Box2D在x轴上左右拖动一个物体。
This is what i have so far which isnt working correctly, the body moves up on the y axis and it doesnt follow the pointer(finger) 这是我到目前为止无法正常工作的内容,身体在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);
Anyone familiar with doing this? 有人熟悉吗?
probably you should use body.getPosition().y
instead of this.getY()
but I don't know how do you get x ? 也许你应该使用body.getPosition().y
代替this.getY()
但我不知道你怎么X? if you use pSceneTouchEvent.getX()
then it sould works 如果您使用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.