2012-03-11 85 views
0

我现场有2层,游戏,按键,具有:设置图层在cocos2d中不可见?

+(CCScene *) scene 
{ 
    // 'scene' is an autorelease object. 
    CCScene *scene = [CCScene node]; 

    // 'layer' is an autorelease object. 
    mainScene *layer = [mainScene node]; 
    buttons *layer2=[buttons node]; 
    layer.tag=30; 
    layer2.tag=40; 
    [scene addChild:layer2 z:1]; 
    [scene addChild: layer]; 

    // return the scene 
    return scene; 
} 

然后我试图让他看不见当触摸屏上用:

[[self getChildByTag:40] setVisible:NO]; 

什么都不发生。

我在做什么错?

非常感谢。

+0

感谢。触摸代码是规则的,并且正在发生,因为我记录它,它: - (void)ccTouchesBegan:(NSSet *)触及事件:(UIEvent *)事件。 getChildByTag是一个很大的类,我不能放在这里,但它会返回零当我登录它,我不能为什么。 – Curnelious 2012-03-11 15:32:57

+0

也许这个线程将有所帮助:http://www.cocos2d-iphone.org/forum/topic/12120 – Jeremy 2012-03-11 15:52:46

回答

1

场景中包含的层,而不是self,所以你需要调用[[[self parent] getChildByTag:40] setVisible:NO];