Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For my game, I have to set highest z index for my sprite. At present, I wrote following code but didn't work for me.

    Sprite houseSprite = new Sprite(pX, pY,
            textureManager.houseBgRegion.deepCopy(),
            mVertexBufferObjectManager);
    attachChild(houseSprite);
    houseSprite.setZIndex(500);
    sortChildren();

My requirement did not satisfied with setting sprite in the HUD. So any how I have to apply highest z index. Also in my game sprites are dynamically generated as per game play.

So members please share your thoughts.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You are either asking, how to set z-index in the scene higher than a z-index in the HUD, or how to set the highest z-index in the scene.

If it is the first option, bad news. There are three layers that have separate z-index. Background, the scene itself and HUD. Actually each Entity can be a layer with their own z-index. Background is always rendered first, then the scene and then HUD. If you set z-index to anything in the scene, HUD and its entities will always be rendered on top of it.

If you are interested in highest z-index in the current scene itself, after you sort the children by the zIndex, simply call

int max zIndex = getLastChild().getZIndex();

That child has the highest zIndex by definition.

share|improve this answer
    
Second option is correct as per my situation. As per your suggestion, I have to each time set z-index when new sprite added to the scene. –  Siddharth Jun 30 '13 at 7:39
    
At last I adopt this option for my game.So I mark it as correct but I have other solution that become useful to other members. andengine.org/forums/gles2/setting-higher-zindex-t12465.html –  Siddharth Jul 4 '13 at 18:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.