0

我有两层称为 alayer 和 blayer,alayer 是父级

alayer.h 中有一个函数

- (void)playGame;

在 alayer.m 中,添加 blayer

- (id)init
{
  if ([super init] == self) {
   Blayer *bLayer = [[bLayer alloc] initWithParent:self];
   [self addChild:bLayer];
 }
 return self;
}

- (void)playGame
{ 
  CCLOG(@"game start");
}

在 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;
 }

单击“开始”按钮时,可以从图层(父级)中删除播放器,但无法调用函数“playGame”,请问您能帮我解决问题吗?谢谢

4

0 回答 0