Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2D Disable CCMenu

I am new to Cocos2d. I gonna create a sample game which has Menu(CClayer) ,in which each menuitems add CClayer as a child to the Menu Layer. Now i add the settings layer as a child to the Menu layer. when i select the settings layer, the touch detected in Menu layer not in settings layer. how to disable CCMenu in Menu Layer.

Menu Layer:Which contains CCMenu ; Settings Layer: which contains also CCMenu;

Help me,

like image 386
Srini Avatar asked Apr 07 '26 07:04

Srini


2 Answers

From your description without codes i can only tell you this line of code..

MenuLayer.yourMenuObj.isTouchEnabled = NO;
like image 137
xuanweng Avatar answered Apr 09 '26 11:04

xuanweng


In my MenuLayer(CCLayer) which has ccmenu declared in Init Method

{
CCMenuItem *Play = [ CCMenuItemFont itemFromString:@"Level Select" target:self   
                                    selector:@selector(toPlay) ];

CCMenuItem *options = [ CCMenuItemFont itemFromString:@"Options" target:self  
                                                    selector:@selector(toSettings) ];

CCMenu  *mainMenu=[CCMenu menuWithItems:startGame,settings,nil];
    [mainMenu alignItemsVertically];
    mainMenu.position = ccp(240,160);
    [self addChild:mainMenu z:1];
}

-(void) toPlay
{
  OptionsLayer *tOptionsLayer=[OptionsLayer node];
  [self addChild:tOptionsLayer z:2];
}

When i touch the "Options" in Menu it shows the OptionsLayer as a child to the MenuLayer. The OptionsLayer have Menu Items , when i touch the Menu items in OptionsLayer , the touch Touched in Menulayer. so again it shows the OptionsLayer. how to disable the touch on menuitems in MenuLayer.

like image 38
Srini Avatar answered Apr 09 '26 12:04

Srini