0

我正在尝试通过旋转关节旋转身体连接,当在我的桌面上按下空格键按钮时。当我将所有条件都放在创建中时它工作正常,但不能按下空格键按钮。这是我的创建方法

            ballBody =createBall();//first body to the joint
            rectBody=createRect();//second body to the joint

            revoluteJointDef = new RevoluteJointDef();
            revoluteJointDef.initialize(ballBody,rectBody,new Vector2(0,0));
            revoluteJointDef.lowerAngle=0;
            revoluteJointDef.upperAngle=0.785f;
            revoluteJointDef.localAnchorA.set(2,0);
            revoluteJointDef.localAnchorB.set(0,6);
            revoluteJointDef.collideConnected=false;

            revoluteJointDef.lowerAngle=-0.734f;
            revoluteJointDef.upperAngle=0.735f;
            revoluteJointDef.maxMotorTorque=100f;
            revoluteJointDef.motorSpeed=-12.6f;
            revoluteJointDef.referenceAngle=0f;
            revoluteJointDef.enableLimit=true;
            joint = world.createJoint(revoluteJointDef);

我在按下空格键按钮后启用电机

  public boolean keyDown(int keycode) {
        if(keycode== Input.Keys.SPACE) {
                   hit();  // call to hit function
        }

这是命中功能

  private void hit(){
        revoluteJointDef.enableMotor=true;
        }

我的渲染方法是这样的

 public void render(float delta) {
        Gdx.gl.glClearColor(0.5f, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        game.batch.setProjectionMatrix(camera.combined);
        world.step(1f/60f, 6, 2);
        debugRenderer.render(world, camera.combined);
        game.batch.begin();
         game.batch.end();
    }

请帮我提出任何建议。

4

1 回答 1

1

我在你的 Create 方法最后一行发现了错误,应该是这样的

revoluteJoint=(RevoluteJoint)world.createjoint(revolutejointDef);

并在命中方法或创建方法中使用 revolutejoint 而不是 revolutejointDef

revoluteJoint.enableMotor=true;
于 2016-09-11T09:23:47.527 回答