-2

I want to add one cclayer on top of another. I have tried this by using following code

+(id) scene
{
CCScene *scene = [CCScene node];

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

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

return scene;
}

but may be there are some mistakes, cuz when i tried to add something on newLayer ,it says using undeclared variable even when ideclared that in .h file also.

Can you please help me with detail code?

stack
  • 951
  • 3
  • 9
  • 23

1 Answers1

2

Instead of doing this in the "scene" class method, add the "new" CCLayer in the -(id)init{} method:

-(id) init {
    self = [super init];
    if (self) {
        GameScreen *newLayer=[GameScreen node];
        [self addChild:newLayer];

         //Other code        

    } return self;
}
Alexander Blunck
  • 1,224
  • 13
  • 17
  • Tried that too.But then,it won't go below that code([self addChild:newLayer];). It continuosly calls the code before adding new layer and after some time crashes. – stack Jul 24 '12 at 06:54
  • Or tell me, can we add two layers in same scene and how? – stack Jul 24 '12 at 07:37
  • thats real strange...usually you can add as many CCLayers as you please...do you mind sharing more of the code? – Alexander Blunck Jul 24 '12 at 11:07