我在這裏有兩個精靈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);
}
}
}
我怎樣才能做到這一點?
您可能需要在添加推土機 – jmroyalty 2013-04-29 12:27:06
之後進行排序,然後在調用bullDozer之後調用sortChildren()。但沒有改變@ jmr499485 – 2013-04-29 12:53:01