Question

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 ..?

Nor the init method in HUD layer is being called.

Any Ideas.. ?

Thanks in advance for your time.

Was it helpful?

Solution

I'm guessing [Hudclass node] isn't calling your class' init method but only the CCNode init method. You can verify this by setting a breakpoint at that line and stepping into the node method.

Two solutions:

  • override +(id)node in your HUDclass
  • create the layer with [[[HUDclass alloc] init] autorelease]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top