[英]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.