2012-07-27 65 views
0

當我不得不移動我的場景有些精靈(例如,在100像素下),我使用這個代碼:如何在Android AndEngine中執行動畫?

Timer timer = new Timer(); 
for (int i=0; i<10; i++) { 
    delay+=frameDelay; 
    timer.schedule(new TimerTask() { 
      @Override 
      public void run() { 
       sprite.setPosition(sprite.getX(), sprite.getY()+10); 
      } 
     },delay); 
} 

它的工作原理,但我不知道是否有很多正確的和/或更快速做到這一點的可能性。

+0

您是否在使用AndEngine? – 2012-07-27 19:21:54

回答

5

還是看提供的各種各樣的改性劑 - 以向上/向下移動,使用MoveYModifier - 像

yourSprite.registerEntityModifier(new MoveYModifier(time, startY, endY, new IEntityModifierListener() { 
       @Override 
       public void onModifierStarted(final IModifier<IEntity> pModifier, final IEntity pItem) { 
        yourActivity.this.runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          //Do anything here that you want to happen when the Modifier starts - like start a sound playing, etc 
         } 
        }); 
       } 

       @Override 
       public void onModifierFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity) { 
        yourActivity.this.runOnUiThread(new Runnable() { 
         @Override 
         public void run() { 
          //Do anything here that you want to happen after the Modifier is through - like stop playing a sound, etc 
          } 
         } 
        }); 
       } 
      }, EaseBounceOut.getInstance())); 

的EaseBounceOut.getInstance()僅僅是一個例子 - 它會導致雪碧在反彈結束 - 有很多其他EaseFunctions可用。