2013-04-16 3 views
0

내가andengine 스프라이트 이동 PathModifier과 몸

 this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 8, 1); 
    this.mScene.registerUpdateHandler(this.mPhysicsWorld);  

    final AnimatedSprite chat_sale_1 = new AnimatedSprite(2157, 638, this.mchatSaleTextureRegion);  

//final PhysicsHandler physicsHandler2 = new PhysicsHandler(chat_sale_1); 
//chat_sale_1.registerUpdateHandler(physicsHandler2); 

      final FixtureDef chat_sale_1FixtureDef = PhysicsFactory.createFixtureDef(0, 0, 0f); 
      mCatBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, chat_sale_1, BodyType.DynamicBody, chat_sale_1FixtureDef); 
      //mCatBody.setColor(1, 0, 0, 0.25f);     


      final Path path = new Path(5).to(2157, 638).to(2775, 638).to(2775, 610).to(2157, 610).to(2157, 638); 
      //207 

      chat_sale_1.registerEntityModifier(
       new LoopEntityModifier(
new PathModifier(35, path, null, new IPathModifierListener() { 

       @Override 
       public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity) { 
        //Debug.d("onPathStarted"); 
       } 

       @Override 
       public void onPathWaypointStarted(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) { 
        switch(pWaypointIndex) { 
        case 0:   
         chat_sale_1.animate(new long[]{200, 200, 200}, 9, 11, true);        
         break; 
        case 1: 
         chat_sale_1.animate(new long[]{200, 200, 200}, 13, 15, true); 
         break; 
        case 2: 
         chat_sale_1.animate(new long[]{200, 200, 200}, 5, 7, true); 
         break; 
        case 3: 
         chat_sale_1.animate(new long[]{200, 200, 200},1, 3, true); 
         break; 
       } 
        //Debug.d("onPathWaypointStarted: " + pWaypointIndex); 
       } 

       @Override 
       public void onPathWaypointFinished(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) { 
        //Debug.d("onPathWaypointFinished: " + pWaypointIndex); 
        //player.stopAnimation(); 
       } 

       @Override 
       public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity) { 
        //Debug.d("onPathFinished"); 
        chat_sale_1.stopAnimation();       
       } 
      },EaseLinear.getInstance())) 
      ); 

      this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(chat_sale_1, mCatBody, true, true){ 
       @Override 
       public void onUpdate(float pSecondsElapsed){ 
        super.onUpdate(pSecondsElapsed); 
        //Log.d(tag, "onUpdate"); 
        //chat_sale_1.setPosition(mCamera.getMinX()+chat_sale_1.getX(), mCamera.getMinY()+chat_sale_1.getY()); 
      //mCatBody.setLinearVelocity(chat_sale_1.getX(),chat_sale_1.getY()); 
        //mCatBody.setLinearVelocity(new Vector2(0,0)); 
        //mCatBody.setTransform(new Vector2(mCamera.getMinX()+chat_sale_1.getX()/32,mCamera.getMinY()+chat_sale_1.getY()/32), 0); 

        //mCatBody.setLinearVelocity(new Vector2(mCamera.getMinX()+chat_sale_1.getX(),mCamera.getMinY()+chat_sale_1.getY())); 
     //final Vector2 velocity2 = Vector2Pool.obtain(chat_sale_1.getX(), chat_sale_1.getY()); 
    //mCatBody.setLinearVelocity(velocity2); 
    //Vector2Pool.recycle(velocity2); 
     mCatBody.setTransform(chat_sale_1.getX()/32,chat_sale_1.getY()/32, 0); 
    //mCatBody.setTransform(new Vector2(chat_sale_1.getX()/mPixelToMeterRatio,chat_sale_1.getY()/mPixelToMeterRatio), 0); 
//final Vector2 velocity2 = Vector2Pool.obtain(mCamera.getMinX()+chat_sale_1.getX(), mCamera.getMinY()+chat_sale_1.getY()); 

    //final Vector2 velocity2 = Vector2Pool.obtain(chat_sale_1.getX(), chat_sale_1.getY()); 
    //mCatBody.setLinearVelocity(velocity2); 
    //Vector2Pool.recycle(velocity2); 
//mCatBody.setTransform(new Vector2(chat_sale_1.getX()/32,chat_sale_1.getY()/32), 0); 
       } 
      }); 

      mScene.attachChild(chat_sale_1);  

코드 드에 mplayer가

mplayer = new Saiyan(playerX, playerY, this.textureRegionHashMap.get("hero5")); 
    //this.mCamera.setChaseEntity(mplayer); 

    physicsHandler = new PhysicsHandler(mplayer); 
    mplayer.registerUpdateHandler(physicsHandler); 

    final FixtureDef playerFixtureDef = PhysicsFactory.createFixtureDef(0, 0, 0f); 
    mPlayerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, mplayer, BodyType.DynamicBody, playerFixtureDef); 

    this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(mplayer, mPlayerBody, true, false){ 
     @Override 
     public void onUpdate(float pSecondsElapsed){ 
      super.onUpdate(pSecondsElapsed); 
      mCamera.updateChaseEntity(); 
     } 
    }); 

    mCamera.setChaseEntity(mplayer); 

    mScene.attachChild(mplayer); 

chat_sale_1의 몸을 따라하는 것은 불가능하고 아무것도에 mplayer와 chat_sale_1으로 발생하지, 이해가 안이 코드를 사용 . 제발 mCatBody에 대한 올바른 코드를 만들어주십시오 제발?

답변

1

즐기 (새 IUpdateHandler() {

     Vector2 localPoint = Vector2Pool.obtain(((chat_sale_1.getX()+(chat_sale_1.getWidth()/2))/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT), ((chat_sale_1.getY()+chat_sale_1.getHeight()-8)/PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT)); 
        mCatBody.setTransform(localPoint, 0); 
        Vector2Pool.recycle(localPoint); 

mScene.registerUpdateHandler에

   final FixtureDef chat_sale_1FixtureDef = PhysicsFactory.createFixtureDef(0, 0, 0f); 
      mCatBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, 8,1, 16,1, 0, BodyType.KinematicBody, chat_sale_1FixtureDef); 

이 해결! 또한

+0

, 참고 : 당신이 장면에서 몸의 위치를 ​​업데이트해야 UpdateHandler ** mPhysicsWorld.registerPhysicsConnector (새로운 PhysicsConnector (hreo, heroBody, true, true) {public void onUpdate (final float pSecondsElapsed) {... ** - 업데이트) – djdance

관련 문제