【问题标题】:stop background layer menu absorbing touches Cocos2D停止背景层菜单吸收触动 Cocos2D
【发布时间】:2012-10-07 23:25:48
【问题描述】:

我使用 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]];
}

如果您需要查看其他内容,请告诉我...但我很确定可以使用上面的代码给出解决方案 :)

【问题讨论】:

    标签: ios xcode cocos2d-iphone


    【解决方案1】:

    您可以在游戏层菜单的检查中创建一个布尔检查以查看它们是否被触摸。例如,由于您使用 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
    }
    

    【讨论】:

    • 简单的解决方案!非常感谢,真的应该亲自到那里!
    【解决方案2】:

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

    e.g.
    
    //ENABLE when settings displayed
    settingsChoiceMenu.isTouchEnabled = TRUE; 
    
    //DISABLE when going back to main scene
    settingsChoiceMenu.isTouchEnabled = FALSE;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多