I have two layer called alayer and blayer, alayer is parent
there is a function in alayer.h
- (void)playGame;
in alayer.m, add blayer
- (id)init
{
if ([super init] == self) {
Blayer *bLayer = [[bLayer alloc] initWithParent:self];
[self addChild:bLayer];
}
return self;
}
- (void)playGame
{
CCLOG(@"game start");
}
in blayer.m
-(id) initWithParent:(CCLayer *)parentLayer
{
if ([super init] == self) {
winSize = [[CCDirector sharedDirector] winSize];
CCLabelTTF *startGameLabel = [CCLabelTTF labelWithString:@"Start" fontName:@"Marker Felt" fontSize:12];
startGameLabel.color = ccc3(251, 182, 59);
CCMenuItemFont *startGame = [CCMenuItemFont itemWithLabel:startGameLabel block:^(id sender) {
[self removeFromParentAndCleanup:YES];
Alayer *aLayer = (Alayer *)self.parent;
[aLayer playGame];
}];
CCMenu *menuStart = [CCMenu menuWithItems:startGame, nil];
menuStart.position = ccp(winSize.width / 2, winSize.height / 2);
[self addChild: menuStart];
}
return self;
}
when click the button 'Start', the blayer can be removed from alayer(parent), but the function 'playGame' can not be called, so can you help me where the problem is? thanks