Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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,

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
LibGDX, Cocos2D or AndEngine? Choose just one tag @Siddharth, please – Gustavo Maciel Sep 8 '14 at 18:38
Okay, I was new at that time so don't know much more things. – Siddharth Sep 10 '14 at 13:33
up vote 2 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. – Siddharth Jul 4 '13 at 18:28

Your Answer


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.