Reputation: 1844
I've created a slide out settings menu for my iPhone app using Cocos2D, by having a layer with a settings menu on it move out over another layer which has the game menu, it's all working perfectly... however you can still click the menu items on the game menu through the settings menu, which to be frank I don't want to be able to do ;) Is there any easy way to set menu items so they don't respond to user input? Or should i create a see-through overlay menu item in the settings menu which will absorb any touches?
Here's my code:
- (void)addButtons: (int) screenSize {
CCMenuItemImage *goPlay = [CCMenuItemImage itemWithNormalImage:@"playButtonUnpressed.png"
selectedImage:@"playButtonPressed.png"
target:self
selector:@selector(onPlay:)];
CCMenuItemImage *goSettings = [CCMenuItemImage itemWithNormalImage:@"settingsButtonUnpressed.png"
selectedImage:@"settingsButtonPressed.png"
target: self
selector:@selector(onSettings:)];
CCMenuItemImage *goFacebook = [CCMenuItemImage itemWithNormalImage:@"facebook.png"
selectedImage:@"facebook.png"
target: self
selector:@selector(onFacebook:)];
CCMenuItemImage *goTwitter = [CCMenuItemImage itemWithNormalImage:@"twitter.png"
selectedImage:@"twitter.png"
target: self
selector:@selector(onTwitter:)];
CCMenuItemImage *goWebsite = [CCMenuItemImage itemWithNormalImage:@"website.png"
selectedImage:@"website.png"
target: self
selector:@selector(onWebsite:)];
CCMenu *play = [CCMenu menuWithItems: goPlay,goSettings,goFacebook,goTwitter,goWebsite,nil];
[self addChild: play];
// Add menu image to menu
play.position = ccp(0,0);
if (self.iPad) {
goPlay.position = ccp(64, 64);
goSettings.position = ccp(128,128);
// Add menu to this scene
}
else if (screenSize < 490){
goPlay.position = ccp(85, 85);
goSettings.position = ccp(235,85);
goFacebook.position = ccp(275,445);
goTwitter.position = ccp(275,402);
goWebsite.position = ccp(275,359);
// Add menu to this scene
}
}
- (void) onSettings: (id) sender{
CGPoint onScreenPoint = ccp(0, 0);
id actionMove = [CCMoveTo actionWithDuration:0.3
position:onScreenPoint];
[_settings runAction:[CCSequence actions:actionMove, nil]];
}
Let me know if you need to see anything else... But I'm pretty sure a solution can be given with the above code :)
Upvotes: 2
Views: 440
Reputation: 9596
I solved this by changing the isTouchEnabled in the menu itself:
e.g.
//ENABLE when settings displayed
settingsChoiceMenu.isTouchEnabled = TRUE;
//DISABLE when going back to main scene
settingsChoiceMenu.isTouchEnabled = FALSE;
Upvotes: 0
Reputation: 234
You could create a bool check in the game layer menus' check to see if their touched. For example since your using the CCMenus just add it inside the selector:
if(!settingsMenuOut)//checks to see if settingsMenuOut (a bool) is false,
//if its true it won't do whatever it normally would.
{
//do the menu stuff
}
Upvotes: 1