2016-09-09 1 views
0

스페이스 바 버튼을 눌렀을 때 회전 조인트를 통해 몸체를 회전하려고합니다. 모든 조건을 작성할 때 desktop.it이 제대로 작동하지만 스페이스 바 버튼을 눌러도 작동하지 않습니다. 여기에 방법을입력 버튼을 사용하여 Revolute joint를 제어하는 ​​방법은 무엇입니까?

  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(); 
    } 

어떤 제안이라도 도와주세요.

답변

1

나는 마지막 줄이 방법을 사용 revolutejoint를 만드는 것보다 다른

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

추천하고 히트 방법에 있거나해야 당신의 작성 방법에 실수를 발견하는 대신 revolutejointDef

revoluteJoint.enableMotor=true; 
관련 문제