1

ここには、easyEnemy と bullDozer の 2 つのスプライトがあります。easyEnemy は毎秒スポーンします。ブルドーザーはランダムなタイミングでやってきます。

ブルドーザーの Zindex = 10 に設定し、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);
        }
    }


}

どうすればこれを達成できますか?

4

1 に答える 1

3

レイヤーの概念を使用してみてください。これはニーズを満たし、非常にシンプルです。
エンティティをレイヤーとして追加し、必要なレイヤーにスプリーを追加する必要があります。
簡単な例を次に示します。

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
}

シーンに 2 つのレイヤーがあり、好きなレイヤーにスプライトを追加します。

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

これは便利なリンクです
もう1つ
、シーンの最初のエンティティとしてレイヤーを追加する必要があることを覚えておいてください

于 2013-04-29T12:41:00.550 に答える