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 create game scene for which I set HUD to it.

First my game scene use BoundCamera, so I use hud to set score text, dollar text and setting button. Now on game scene when I touch on setting button, the child scene (setting scene) come up because I attached it to game scene.

I use child scene because of pause/resume functionality added to the setting scene.

When child scene display on the screen at the same time hud content also displayed on the sceeen. But I don't want that hud content of my child scene (setting scene).

From other post of this forum I found that made hud.setVisible(false).

But this solution does not work for me because the touch area of hud's children remain active even though it were not displayed on the screen. So when player touch on these areas the effect of touch become available even if the hud is not displayed on the screen.

Also I like to mention that my development platform is AndEngine. I hope someone give me best guidance on this.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I don't know why this question was tagged with cocos2d-iphone, but here it is the answer for cocos2d-iphone:

In cocos2d you solve this problem by using the Z index ordering. Layers with lower Z index get rendered first.

Check the Cocos2D 2.0 Docs.

//kGameLayer 
[self addChild:[GameLayer node] z:0 tag:KGameLayer];

//kHudLayer 
[self addChild:[HudLayer node] z:1 tag:KHudLayer];

//kTopLayer 
[self addChild:[TopLayer node] z:2 tag:KTopLayer];

Now in order to show/hide a layer you can use the visible property of a node, check the documentation.

@implementation HudLayer                               

-(void) showLayer: (BOOL) shouldShow
{
  self.visible = shouldShow;
  self.isTouchEnabled = shouldShow;
  menu.isTouchEnabled = shouldShow;
}
@end

Now when you display the menu and want to hide the HudLayer, you only have to get the HudLayer by tag, and call shwoLayer with NO.

AndEngine

In AndEngine you should be able to set the isVisible property of the HudLayer to false, check the source code of BaseEntity

public boolean isVisible() {
  return this.mVisible;
}

public void setVisible(final boolean pVisible) {
  this.mVisible = pVisible;
}

I assume that the HudLayer in AndEngine is a Layer object, and as I checked the Layer object is a subclass of BaseEntity, hence you should be able to call setVisible on the HudLayer.

share|improve this answer
    
I up vote your answer because you give some concept that is important for us. But this thing does not work in andengine. Because zIndex of hud is higher by default. –  Siddharth Jan 17 '13 at 16:21
    
check my latest edit. Overall I think that your only chance is to browse through the Andengine source code. –  Andrei T. Ursan Jan 17 '13 at 16:34

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.