2012-01-18 74 views
2

我有以下代碼讓精靈跟隨使用Andengine的路徑。我需要改變沿路徑()移動的精靈的速度(速度)。有誰知道如何改變沿路徑的速度?andengine path修飾速度

private void follow_path5(final AnimatedSprite tSprite,int i) { 
    final Path path = new Path(5) 
    .to(20, startY) 
    .to(416.0f, startY) 
    .to(20.0f, startY) 
    .to(416.0f,startY) 
    .to(20.0f,startY); 

    // Add the proper animation when a waypoint of the path is passed. 
    tSprite.registerEntityModifier(new PathModifier(30.0f, path, null, new IPathModifierListener() { 
     @Override 
     public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity) { 

     } 

     @Override 
     public void onPathWaypointStarted(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) { 

      switch(pWaypointIndex) { 
      case 0: case 1: case 2: case 3: 
       final long[] frameDurations = new long[3]; 
       Arrays.fill(frameDurations, 500); 
       tSprite.animate(frameDurations, 2, 4, true); 

       break; 

      case 4: case 5: case 6: case 7: 
       final long[] frameDurations1 = new long[3]; 
       Arrays.fill(frameDurations1, 500); 
       tSprite.animate(frameDurations1, 5, 7, true); 

       break; 

      case 8: case 9: case 10: case 11: 
       final long[] frameDurations2 = new long[3]; 
       Arrays.fill(frameDurations2, 500); 
       tSprite.animate(frameDurations2, 2, 4, true); 

       break; 

      case 12: case 13: case 14: 
       final long[] frameDurations3 = new long[3]; 
       Arrays.fill(frameDurations3, 500); 
       tSprite.animate(frameDurations3, 5, 7, true); 

       break; 
      } 
     } 

     @Override 
     public void onPathWaypointFinished(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) { 

     } 

     @Override 
     public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity) { 
     }})); 
    scene.attachChild(asprVamp[i]); 
} 
+0

我也部分地使用可運行()來運行其他路徑負方向沿精靈在這工作,但產生略顯生澀的動畫 – ITECH 2012-01-18 10:00:08

+0

多麼可愛的黑客隨機間隔行駛路徑稍微移動解決這個,我從來沒有想過這個:-) – JohnEye 2012-10-08 10:02:38

回答

2

你只能給出移動的持續時間,每個路徑修飾符1個。所以,如果你想在不同的路徑點有不同的速度,你必須創建不同的路徑修改器。

+0

謝謝你是對的我期待修改沿途的速度,但實際上我只需要稍微隨意改變持續時間,以給出移動速度稍微不同的精靈的印象。有時不能看見樹木。感謝那。 – ITECH 2012-01-18 15:58:41

1

我對類似的問題是從原來的修改派生並添加因子通過時間的解決方案:

@Override 
public float onUpdate(float pSecondsElapsed, IEntity pItem) { 
    return super.onUpdate(pSecondsElapsed*frequency, pItem); 
} 
2

您可以使用SequenceEntityModifier不同的實體修飾符合併成一個,這將滿足,因爲你的要求每個PathModifier可以有不同的時間長度。

Path a = new Path(2).to(0, 0).to(400,0); 
    Path b = new Path(2).to(400, 0).to(800, 0); 

    IEntityModifier[] modifier = new IEntityModifier[2]; 
    modifier[0] = new PathModifier(3, a); 
    modifier[1] = new new PathModifier(1, b); 

    IEntityModifier entMod = new SequenceEntityModifier(modifier); 
    entity.registerEntityModifier(entMod); 
    scene.attachChild(entity);