2013-08-17 1 views
0

플레이어가 파워 어택을 해제하는 문제가 있습니다.이 파워 어택은 특정 위치로 이동 한 다음 분리되어야합니다. 어떻게이 작업을 수행 할 수 있습니까? 나는 setvelocity를 사용하여 시도했지만 잘 작동하지 않았다 ... pls 도움 !! 난 특별한 공격 몸이 화면 밖으로 이동이 코드를 실행하면버튼을 눌렀을 때 한 위치에서 다른 위치로 몸체 이동

공공 무효 powerattack() {

float startBulletX = player.getX() + 30; //Get X position of character body 
    float startBulletY = player.getY();  //Get Y position of character body 

    final Sprite bullet = new Sprite(startBulletX, startBulletY, 
      resourcesManager.special_attack, vbom); //The special attack sprite 

    final FixtureDef bulletFixtureDef1 = PhysicsFactory.createFixtureDef(0, 
      0, 0, false, CATEGORYBIT_KNIFE, MASKBIT_KNIFE, (short) 0); 
    this.mBulletBody = PhysicsFactory.createBoxBody(physicsWorld, bullet, 
      BodyType.DynamicBody, bulletFixtureDef1); 

    mBulletBody.setLinearVelocity(20f,0); 

    this.physicsWorld.registerPhysicsConnector(new PhysicsConnector(bullet, 
      this.mBulletBody, true, false)); 


    this.attachChild(bullet); 

} 

.. : 좋아

여기에 버튼을 누를 때 호출되는 내 공격 방법이다 나는 특정 위치, 즉 캐릭터로부터의 거리가 멀어 지도록 파워 어택을 제한하고 싶다.

답변

0

내가, 내가 방법을 솔루션의 onUpdate 익숙해 그의 OnUpdate 메소드 내 전으로 보이지 않는 코드를 설정, 여기에 내 코드 :

public void powerattack() { 

    float startBulletX = player.getX() + 30; 
    float startBulletY = player.getY(); 

    final Sprite ray = new Sprite(startBulletX, startBulletY, 
      resourcesManager.special_attack, vbom); 
    final Vector2 velocity = Vector2Pool.obtain(20f, 0); 
    final FixtureDef rayFixtureDef1 = PhysicsFactory.createFixtureDef(0, 0, 
      0, false, CATEGORYBIT_RAY, MASKBIT_RAY, (short) 0); 
    this.mRayBody = PhysicsFactory.createBoxBody(physicsWorld, ray, 
      BodyType.DynamicBody, rayFixtureDef1); 

    this.mRayBody.setLinearVelocity(velocity); 
    Vector2Pool.recycle(velocity); 

    this.physicsWorld.registerPhysicsConnector(new PhysicsConnector(ray, 
      this.mRayBody, true, false) { 
     /*Update method keeps checking whether the power attack reached the specific distance*/ 
     @Override 
     public void onUpdate(float pSecondsElapsed) { 

      if (ray.getX() >= (player.getX() + 300)) { 

       ray.setVisible(false); 
       ray.setIgnoreUpdate(false); 

      } 
      super.onUpdate(pSecondsElapsed); 
      camera.onUpdate(0.1f); 
     } 
    }); 

    mRayBody.setUserData("power"); 
    this.attachChild(ray); 

} 
입니다
관련 문제