2011-04-25 93 views
0

我正在使用andengine通過box2d創建物理模擬。座標系和精靈轉換

這些物體是通過PhysicsFactory使用Sprites創建的。

我的想法是程序上定位這些精靈,下面這個模式:rotation around externalPoint

代表我的世界座標中心基本上是一箇中央的精靈,而且是通過繞myWorld中心基地精靈創造了一系列克隆精靈(圓圈內的「X」)。

我試圖使用OpenGL方式中andengine(平移,旋轉,後翻譯)

super(stamiRadious, 0, image);  //stamiDoadious is te distance from radix (world center) and "petal" attach point 
this.setRotationCenter(0, 0); 
this.setRotation((float) Math.toDegrees(angleRad)); 
this.setPosition(this.getX()+radixX, this.getY()+radixY); 

但我失敗了:結果不正確的(錯誤的最終位置,和錯誤的Box2D的身體財產,猶如該精靈比圖像大得多)

我相信部分問題依賴於我對setRotationsetRotationCenter的解釋,並且一般以我對andengine座標系統+ box2d座標系統的理解爲依據。

任何想法/鏈接到doc /解釋?

回答

4

一旦你創建了一個Sprite的Physics representation(Body),你應該非常小心修改Sprite!通常你不會修改雪碧了可言,而是通過調用

someBody.setTransform(); // Note that positions must be divided by PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT! 

希望這有助於:)

修改身體,