2013-01-17 103 views
0

嗨,我使用和發動機在這裏當我點擊按鈕,那個時候我需要提出兩項精靈精靈正在細做一個應用程序,但我的要求,現在這兩個精靈在相反的方向時,點擊按鈕都精靈要在這兩個精靈有一些100的距離,我想停止使用animation.i下面的代碼嘗試,但其caluculating開始精靈的位置,在移動時它不是caluculating烈酒志願服務崗位可以ü任何一個幫我搬然後屏幕中心....如何移動精靈在andengine

final float centerX = (CAMERA_WIDTH - this.mPaddleTextureRegionbtn.getWidth()); 
    final float centerY = (CAMERA_HEIGHT - this.mPaddleTextureRegionbtn.getHeight())/2; 
    paddle = new Sprite(centerX, centerY, this.mPaddleTextureRegionbtn, this.getVertexBufferObjectManager()); 
    final PhysicsHandler physicsHandler = new PhysicsHandler(paddle); 
    paddle.registerUpdateHandler(physicsHandler); 
scene.attachChild(paddle); 

final AnimatedSprite banana = new AnimatedSprite(0, centerY, this.mBananaTextureRegion, this.getVertexBufferObjectManager()); 
    banana.animate(100); 
    scene.attachChild(banana); 

    final float centerX1 = (CAMERA_WIDTH - this.mPaddleTextureRegion1.getWidth())/38; 
     final float centerY1 = (CAMERA_HEIGHT - this.mPaddleTextureRegion1.getHeight()) /7; 


    ButtonSprite moveRightButton = new ButtonSprite(centerX1, centerY1, this.mPaddleTextureRegion1, this.getVertexBufferObjectManager(), new OnClickListener() { 

     @Override 
     public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, 
         float pTouchAreaLocalY) {  
      runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
        Toast.makeText(Pong.this, "Haiii-------------", Toast.LENGTH_LONG).show(); 




        MoveXModifier mod = new MoveXModifier(2, banana.getX(), paddle.getX()-100); 
        banana.registerEntityModifier(mod); 


        MoveXModifier mod1 = new MoveXModifier(2, paddle.getX(),banana.getX()+100); 

        paddle.registerEntityModifier(mod1); 

       } 
      }); 
     } 
}); 



    scene.attachChild(moveRightButton); 
    scene.registerTouchArea(moveRightButton); 
    scene.setTouchAreaBindingOnActionDownEnabled(true); 

回答

0

試試這個,它可以幫助你。

MoveXModifier MOD =新MoveXModifier(2 banana.getX(),paddle.getX() - 100,新IEntityModifierListener(){

 @Override 
     public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) 
     { 

     } 

     @Override 
     public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) { 

      banana.stopAnimation(); 
     } 
    }); 
       banana.registerEntityModifier(mod); 

同樣可以爲下一次做

希望你的問題的這個答案,我可以理解。

+0

thnku。我會努力 – user1089640