0

有没有办法在不使用 body.setTransform() 方法的情况下围绕与身体中心不同的点旋转运动体?因为当我使用 setTransform() 物理行为变得奇怪。我使用andengine。

4

2 回答 2

1

它旋转的点会改变吗?如果不是,您可以从身体中心偏移身体的形状。然后当身体旋转时,它将围绕该点旋转。

另一个想法是使用关节。(*在下面指出)

于 2013-09-18T20:00:09.190 回答
0

您可以将方程式用于圆的 x 和 y 坐标。如果您使用下面的示例代码,场景上的每次触摸都会导致角度减少 0.1,这将导致身体围绕点(xCenteryCenter)旋转,半径为r

private float p2m = PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT;

@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {

    angle -= 0.1;

    Vector2 vector = Vector2Pool.obtain(xCenter/p2m + (r/p2m) * Math.cos(angle), (yCenter/p2m + (r/p2m) * Math.sin(angle));
    body.setTransform(vector, angle);
    Vector2Pool.recycle(vector);
    return false;
}
于 2013-09-26T15:57:08.720 回答