Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top