Cocos2d-x CCMenuItemToggle对touchend而不是touchbegan的响应

时间:2014-03-27 05:08:35

标签: android ios cocos2d-x

触摸后,我的切换菜单项会立即响应。我希望它在触摸结束时做出响应,即当我拿起手指时。有任何想法吗???? 这是我的代码

CCMenuItemSprite* p1 = CCMenuItemSprite::create(CMBaseSprite::initWithBaseSprite("ss_On"), CMBaseSprite::initWithBaseSprite("ss_off"));
CCMenuItemSprite* p2 = CCMenuItemSprite::create(CMBaseSprite::initWithBaseSprite("ss_off"), CMBaseSprite::initWithBaseSprite("ss_On"));
CCMenuItemToggle* pSoundToggle = CCMenuItemToggle::createWithTarget(this, menu_selector(SettingsLayer::turnOnOffMusic), p1, p2, NULL);
pSoundToggle->setPosition(ccp(settingsLayerSprite->getContentSize().width * 0.5, settingsLayerSprite->getContentSize().height* 0.62));
pSoundsMenu->addChild(pSoundToggle);

1 个答案:

答案 0 :(得分:0)

它在IOS中工作正常,因为您只需要在触摸端激活。这就是例如。

    CCMenuItem *soundOnItem = [CCMenuItemImage itemWithNormalImage:@"soundOn.png"
                                                     selectedImage:@"soundOn.png"];

    CCMenuItem *soundOffItem = [CCMenuItemImage itemWithNormalImage:@"soundOff.png"
                                                      selectedImage:@"soundOff.png"];

CCMenuItemToggle *soundToggleItem;
 if ([[NSUserDefaults standardUserDefaults]boolForKey:@"sound"])
        soundToggleItem = [CCMenuItemToggle itemWithTarget:self    
                                                  selector:@selector(sound)    
                                                  items:soundOnItem,
                                                  soundOffItem, nil];
    else
        soundToggleItem = [CCMenuItemToggle itemWithTarget:self
                                                  selector:@selector(sound) 
                                                  items:soundOffItem, 
                                                  soundOnItem, nil];