0

我已经在 Andengine 论坛上发布了这个问题,但是已经有一些关于这个主题的问题,有些有回复,但我想知道的还没有任何回复。

我正在尝试模拟像超级马里奥兄弟中那样的玩家跳跃。首先,我使用了一个简单的接触监听器,当接触发生但接触发生在墙壁地面时,我使用了一个布尔值 false,一切。所以,我现在尝试使用 WeldJoint 将另一个小身体连接到播放器底部作为脚部传感器。但我无法做到这一点。WeldJoint 根本不会粘住。我试图在更新线程上创建 WeldJoint,没有。我尝试使用 setposition 方法用玩家的位置更新传感器位置,但它只是将传感器定位在地下。任何建议,将不胜感激。这是我尝试创建 WeldJoint 的方法。

播放器和传感器

mPlayer = new AnimatedSprite(100, 150, PlayerTextureRegion);
PlayerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld,mPlayer,BodyType.DynamicBody, PLAYER_FIXTURE_DEF);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mPlayer, PlayerBody, true, true));
mScene.getLastChild().attachChild(mPlayer);

final Shape mSensor= new Rectangle(mPlayer.getX()+4,mPlayer.getY()+mPlayer.getHeight(),10,4);
final Body SensorBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld,mSensor,BodyType.DynamicBody, SENSOR_FIXTURE_DEF);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mSensor, SensorBody, true, true));
mScene.getLastChild().attachChild(mSensor);

mScene.registerUpdateHandler(new IUpdateHandler() {

        @Override
        public void reset() { }

        @Override
        public void onUpdate(final float pSecondsElapsed) {
             this.createJoint(PlayerBody,SensorBody);
             .......

联合法

private void createJoint(Body Anchor, Body Sensor){
    final WeldJointDef join = new WeldJointDef();
    join.initialize(Anchor,Sensor,Anchor.getWorldCenter());
    this.mPhysicsWorld.createJoint(join);
}
4

1 回答 1

1

好的,我使用 RevoluteJoint 而不是 WeldJoint,没有电机配置,现在它工作正常。只需使用 revoluteJointDef 初始化两个物体,它们就会像焊接接头一样被卡住。暂时我将使用 revoluteJoint 将两个身体合二为一。

于 2011-08-05T13:50:27.293 回答