Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a CCScene which already holds my gameLayer and I am trying to add HUD layer on that.But the HUD layer is not getting added in my scene, I can say that because I have set up a CCLabel on HUD layer and when I run my project, I cannot see that label.

Here's what I am doing : In my gameLayer:

+(id) scene
{

   CCScene *scene = [CCScene node];

   GameScreen *layer = [GameScreen node];
   [scene addChild: layer];

    HUDclass * otherLayer = [HUDclass node];
    [scene addChild:otherLayer];

    layer.HC = otherLayer;// HC is reference to my HUD layer in @Interface of gameLayer
    return scene;
}

And then in my HUD layer I have just added a CCLabelTTF in its init method like this :

-(id)init {

    if ((self = [super init])) {

    CCLabelTTF * label = [CCLabelTTF labelWithString:@"IN WEAPON CLASS" fontName:@"Arial"    fontSize:15];
     label.position = ccp(240,160);
     [self addChild:label];

    }

    return  self;
}

But now when I run my project I dont see that label, What am I doing wrong here ..?

Any Ideas.. ?

Thanks in advance for your time.

share|improve this question
Did you use the debugger? Or at least some logging to see if your HUD layer is actually being created? – bummzack Aug 30 '12 at 14:28

closed as too localized by bummzack, Byte56, John McDonald, Yannbane, michael.bartnett Oct 9 '12 at 2:56

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

In AppDelegate.mm file

[[CCDirector sharedDirector] runWithScene: scene]; Replace this line with

[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];

And define

-(id)initWithHUD:(HUDLayer *)hudLayer;

Method in HelloWorldLayer.h and also create object of HUDLayer in .h file

And replace -(id)init method with -(id)initWithHUD:(HUDLayer *)hudLayer;

and in this method define object of HUDLater *hud define in .h in

hud=hudLayer;
share|improve this answer
-1. This isn't needed at all. Personally I also prefer to not use a HelloWorldLayer in my code. By reading question the code in AppDelegate.m probably should read [[CCDirector sharedDirector] runWithScene: [GameLayer scene]]. Nothing more required. – bummzack Aug 30 '12 at 14:33

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