我已经使用 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]];
}
如果您需要查看其他内容,请告诉我......但我很确定可以使用上面的代码给出解决方案:)