2
\$\begingroup\$

I'm developing an Android game and have some troubles: I want to add some foreground sprites, that must obstruct my player.

Se the following example: Its a screenshot from "Shinobi 3". We can see the player, the enemy, the background and two foreground trees, that hide the player's arm and part of the enemy.

I'm using AndEngine GLES2 Anchor Center and I am trying to add a new layer to my scene.

Sprite Forest = new Sprite(getWidth() * 0.5f, textureHeightForest * 0.5f + 100, ResourcesManager.getInstance().foreground_forest_region, vbom);
Entity foregroundLayer = new Entity();
foregroundLayer.attachChild(hillFurthest);
attachChild(foregroundLayer);

But it still shows behind my player sprite. I am trying to find something in HUD-class (it's always shown in the foreground), but got no results. Can anyone help please?

\$\endgroup\$
1
\$\begingroup\$

You can add the sprites directly to the scene and set their z-index to higher value than the player. Then simply call scene.sortChildren() and the trees will be in front. Also if you add the trees last, they will obstruct your player.

More sophisticated version of this is to use a custom parallax layer that will be added with higher z-index and that would even create the 3D effect.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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