停止背景图层菜单吸收触摸Cocos2D

时间:2012-10-07 23:25:48

标签: ios xcode cocos2d-iphone

我使用Cocos2D为我的iPhone应用程序创建了一个滑出设置菜单,通过在其上设置一个设置菜单的图层移出另一个具有游戏菜单的图层,它完全正常工作...但是你可以仍然通过设置菜单点击游戏菜单上的菜单项,坦白说我不想做;)有没有简单的方法设置菜单项,以便他们不响应用户输入?或者我应该在设置菜单中创建一个可以吸收任何触摸的透明叠加菜单项?

这是我的代码:

- (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]];
}

如果您需要查看其他内容,请告诉我......但我很确定上述代码可以提供解决方案:)

2 个答案:

答案 0 :(得分:1)

您可以在游戏图层菜单中创建一个bool检查以查看是否触摸了它们。例如,因为您使用CCMenus只需将其添加到选择器中:

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
}

答案 1 :(得分:0)

我通过更改菜单本身的isTouchEnabled解决了这个问题:

e.g.

//ENABLE when settings displayed
settingsChoiceMenu.isTouchEnabled = TRUE; 

//DISABLE when going back to main scene
settingsChoiceMenu.isTouchEnabled = FALSE;