0

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

yegomo
  • 297
  • 2
  • 11
  • what do you mean "can not be called"? If there's an error message or compiler warning/error associated with it, copy & paste that message. PS: the convention is to start class names with an uppercase letter, method names and variables start with lowercase letters, every other letter starting a word is upper case (camel-casing). For example: class MyLayer rather than mylayer, and "MyLayer* myLayer" for the variable. – CodeSmile Nov 05 '13 at 17:12
  • @LearnCocos2D thanks for reply, "can not be called" means when I click Start button, there's no response, the log 'CCLOG(@"game start");' can not be printed, i have changed upper and lowercase letters, but it still doesn't work. – yegomo Nov 05 '13 at 23:03
  • Set a breakpoint, check if the block runs and aLayer is not nil. – CodeSmile Nov 06 '13 at 01:08

0 Answers0