0

我想对 AndEngine revoluteJoint 示例进行一些说明。在下面的代码中,connectionLine 具有 x1,y1 和 x2,y2 相同的值。所以这应该创建一个点。为什么这样做?

final Line connectionLine = new Line(anchorFaceX + spriteWidth / 2, anchorFaceY +
spriteHeight / 2, anchorFaceX + spriteWidth / 2, anchorFaceY + spriteHeight / 2, 
this.getVertexBufferObjectManager());

下面的 setPosition 做了什么?它是否会变换线条以使其看起来在旋转?

this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(anchorFace, 
anchorBody, true, true){
@Override
public void onUpdate(final float pSecondsElapsed) {
super.onUpdate(pSecondsElapsed);
final Vector2 movingBodyWorldCenter = movingBody.getWorldCenter();
connectionLine.setPosition(connectionLine.getX1(), connectionLine.getY1(),   
 movingBodyWorldCenter.x * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, 
movingBodyWorldCenter.y * PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);

}
});

我将不胜感激。我需要创建一条在身体移动时与身体刚性连接的线。

4

1 回答 1

0

我能够将身体与在身体移动时保持连接的线连接起来,如下所示

// Join adjacent bodies
          if(i > 0) {
                 connectionLine[i] = new Line(centers[i][0],centers[i][1],centers[i-1][0],centers[i-1][1],lineWidth,this.getVertexBufferObjectManager());
                 connectionLine[i].setColor(0.0f,0.0f,1.0f);
                 this.mScene.attachChild(connectionLine[i]);     

          }

          // Join the first body with the last body
          if(i == 19){
              connectionLine[0] = new Line(centers[0][0],centers[0][1],centers[19][0],centers[19][1],lineWidth,this.getVertexBufferObjectManager());
              connectionLine[0].setColor(.0f,.0f,1.0f);
              this.mScene.attachChild(connectionLine[0]);   
          }

          // Update connection line so that the line moves along with the body
          this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(circle[i], circleBody[i], true, true) {
              @Override
                public void onUpdate(final float pSecondsElapsed) {
                    super.onUpdate(pSecondsElapsed);
                    for(int i=1;i < nBodies;i++) {
                        connectionLine[i].setPosition(circle[i].getX(),circle[i].getY(),circle[i-1].getX(),circle[i-1].getY());

                    }
                    connectionLine[0].setPosition(circle[0].getX(),circle[0].getY(),circle[19].getX(),circle[19].getY());
                }
          }       

        );
于 2013-01-16T04:40:41.297 回答