2013-04-29 33 views
1

我在這裏有兩個精靈easyEnemy & bullDozer。 easyEnemy每秒產卵一次。推土機隨機進入。在場景中頂層設置sprite

我設置推土機Zindex = 10 & for easyEnemy我什麼也沒做。

我想顯示推土機上面所有easyEnemy。但它不起作用。在調用場景中的推土機之前,我打電話給sortChildren()。但這沒有意義。

public class Bulldozer extends PixelPerfectAnimatedSprite { 

public Bulldozer(float pX, float pY, 
     PixelPerfectTiledTextureRegion pTiledTextureRegion, 
     VertexBufferObjectManager pVertexBufferObjectManager) { 
    super(pX, pY, pTiledTextureRegion, pVertexBufferObjectManager); 

    // SET z-INDEX FOR THIS 
    setZIndex(20); 
} 
} 

在GameScene中,我稱之爲easyEnemy和bullDozer。首先調用easyEnemy然後bullDozer。

編輯:添加代碼

class GameScene extends Scene{ 
GameScene(){ 
// constructor 
createEasyEnemy(); 

CreateBullDOzer(); 

sortChildren(); 

} 
public synchronized void createEasyEnemy(final float attackDuration, 
      final float minTime, final float maxTime) { 

     try { 

      float delayTimer = attackDuration; 
      aTimerHandler = new TimerHandler(delayTimer, true, 
        new ITimerCallback() { 
         @Override 
         public void onTimePassed(TimerHandler pTimerHandler) { 
          // 
          isEasyEnemyCreated = true; 
          engine.unregisterUpdateHandler(pTimerHandler); 

          final EasyEnemy aEasyEnemy = aEasyEnemyPoolObj 
            .obtainPoolItem(); 
          if (!aEasyEnemy.hasParent()) { 
           attachChild(aEasyEnemy); 
          } 
          aEasyEnemy.init(minTime, maxTime); 
          registerTouchArea(aEasyEnemy); 
          easyEnemyLinkedList.add(aEasyEnemy); 
         } 
        }); 

      registerUpdateHandler(aTimerHandler); 
     } catch (Exception e) { 
      Log.e("--CreateEasyEnemy-Error", "" + e); 
     } 
    } 


} 

我怎樣才能做到這一點?

+0

您可能需要在添加推土機 – jmroyalty 2013-04-29 12:27:06

+0

之後進行排序,然後在調用bullDozer之後調用sortChildren()。但沒有改變@ jmr499485 – 2013-04-29 12:53:01

回答

3

嘗試使用層concepts.This將滿足您的需求,它很簡單..
您需要添加實體層和添加spries任何層你想
下面是一個簡單的例子

final int FIRST_LAYER = 0; 
final int SECOND_LAYER = 1; 

private void createLayers() 
{ 
    scene.attachChild(new Entity()); // First Layer 
    scene.attachChild(new Entity()); // Second Layer 
} 

現在你有在現場兩層​​加雪碧你喜歡

scene.getChildByIndex(FIRST_LAYER).attachChild(yourEntity); 

This one is a useful link任何層,
一個更次ing
請記住,您需要添加圖層作爲場景中的第一個實體

+0

它第一次正常工作。但是當我重新開始遊戲時,我看不到easyEnemy。但bulldozer像往常一樣。在Log貓中,它顯示easyEnemy Come @ Renjith K N – 2013-04-29 13:22:49

+0

easyEnemy的x,y位置如何? – 2013-04-30 04:31:52

+0

第一次easyEnemy也會隨機移動並生成。那裏沒問題。推土機放在easyEnemy之上。但是我不能在重啓後看到easyEnemy ..儘管推土機也來了!@Renjith – 2013-04-30 05:04:35