本文整理汇总了C++中CCMenuItemToggle::setSelectedIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemToggle::setSelectedIndex方法的具体用法?C++ CCMenuItemToggle::setSelectedIndex怎么用?C++ CCMenuItemToggle::setSelectedIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemToggle
的用法示例。
在下文中一共展示了CCMenuItemToggle::setSelectedIndex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeMenu
void ConfigMenu::makeMenu(){
CCMenuItemFont::setFontSize(50);
CCMenuItemFont::setFontName("Arial");
//CCMenuItemToggle* music = CCMenuItemToggle::createWithTarget(this, menu_selector(ConfigMenu::musicMenuCallback),
//CCMenuItemFont::create("Music OFF"),
//CCMenuItemFont::create("Music ON"), NULL);
CCMenuItemToggle* music = CCMenuItemToggle::createWithTarget(this, menu_selector(ConfigMenu::musicMenuCallback),
CCMenuItemLabel::create(CCLabelBMFont::create("Music OFF", "arial-unicode-26.fnt", 300)),
CCMenuItemLabel::create(CCLabelBMFont::create("Music ON", "arial-unicode-26.fnt", 300)), NULL);
CCLabelBMFont* txtShare = CCLabelBMFont::create("Share", "arial-unicode-26.fnt", 300);
//CCMenuItemFont* share = CCMenuItemFont::create("Share", this, menu_selector(ConfigMenu::shareMenuCallback));
//CCLabelTTF* d = CCLabelTTF::create("Share", "Arial", 30);
CCMenuItemLabel* share = CCMenuItemLabel::create(txtShare, this, menu_selector(ConfigMenu::shareMenuCallback));
music->setPosition(ccp(0,-60));
share->setPosition(ccp(0, music->getContentSize().height+music->getPositionY()+20));
share->setScale(2);
music->setScale(2);
CCMenu *menu = CCMenu::create(music, share, NULL);
//menu->setPosition(ccp(400,0));
menu->setOpacity(kCCMenuHandlerPriority);
this->addChild(menu);
if(!CCUserDefault::sharedUserDefault()->getBoolForKey(CONFIG_KEY_HAS_MUSIC)){
music->setSelectedIndex(1);
}else{
music->setSelectedIndex(0);
}
}
示例2: setToggleStateByNodeIndex
void IOSStoreLayer::setToggleStateByNodeIndex(int iNodeIndex)
{
CCMenuItemToggle* pToggle = NULL;
CCNode* pNode = NULL;
for (int i = 0; i < 2; ++i)
{
pNode = m_pBg->getChildByTag(kaibaoxiang_node_tag+i);
pToggle = (CCMenuItemToggle*)m_pBgMenu->getChildByTag(kaibaoxiang_toggle_tag+i);
if (iNodeIndex == i)
{
if (pNode)
{
// pNode->setVisible(true);
// this->setTableViewVisble(pNode, (void*)true);
pToggle->setSelectedIndex(1);
}
}
else
{
if (pNode)
{
// pNode->setVisible(false);
// this->setTableViewVisble(pNode, (void*)false);
pToggle->setSelectedIndex(0);
}
}
}
}
示例3: setupViews
void OptionLayer::setupViews()
{
//Ìí¼Ó±³¾°Í¼Æ¬
setBackImage("loading.png");
CCSprite* pTitle = CCSprite::create("menuTitle.png", CCRectMake(0, 0, 133, 36));
pTitle->setPosition(ccp(getSize().width/2, getSize().height/2 + 40));
addChild(pTitle);
CCMenuItemToggle* pItem = CCMenuItemToggle::create(this, menu_selector(OptionLayer::Music_Func),
CCMenuItemFont::create("Music : On"),
CCMenuItemFont::create("Music : Off"),
NULL);
CCMenu* pMenu = CCMenu::create(pItem, NULL);
pMenu->setPosition(ccp(getSize().width/2, getSize().height/2-20));
addChild(pMenu);
if(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
pItem->setSelectedIndex(1);
else
pItem->setSelectedIndex(0);
//Ìí¼Ó·µ»Ø°´Å¥
CCLabelBMFont* pFnt = CCLabelBMFont::create("<--Go Back", "arial-14.fnt");
CCMenuItemLabel* pLabel = CCMenuItemLabel::create(pFnt, this, menu_selector(OptionLayer::GoBack_Func));
CCMenu* pMenuBack = CCMenu::create(pLabel, NULL);
pMenuBack->setPosition(ccp(getSize().width/2, getSize().height/2 - 150));
addChild(pMenuBack);
}
示例4: addChild
NotificationCenterTest::NotificationCenterTest()
: m_bShowImage(false)
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this,
menu_selector(NotificationCenterTest::toExtensionsMainLayer));
pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL);
pBackMenu->setPosition( CCPointZero );
addChild(pBackMenu);
CCLabelTTF *label1 = CCLabelTTF::create("switch off", "Marker Felt", 26);
CCLabelTTF *label2 = CCLabelTTF::create("switch on", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::toggleSwitch), item1, item2, NULL);
// turn on
item->setSelectedIndex(1);
CCMenu *menu = CCMenu::create(item, NULL);
menu->setPosition(ccp(s.width/2+100, s.height/2));
addChild(menu);
CCMenu *menuConnect = CCMenu::create();
menuConnect->setPosition(CCPointZero);
addChild(menuConnect);
for (int i = 1; i <= 3; i++)
{
Light* light = Light::lightWithFile("Images/Pea.png");
light->setTag(kTagLight+i);
light->setPosition(ccp(100, s.height/4*i));
addChild(light);
CCLabelTTF *label1 = CCLabelTTF::create("not connected", "Marker Felt", 26);
CCLabelTTF *label2 = CCLabelTTF::create("connected", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::connectToSwitch), item1, item2, NULL);
item->setTag(kTagConnect+i);
item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50));
menuConnect->addChild(item, 0);
if (i == 2)
{
item->setSelectedIndex(1);
}
bool bConnected = item->getSelectedIndex() == 1 ? true : false;
light->setIsConnectToSwitch(bConnected);
}
CCNotificationCenter::sharedNotificationCenter()->postNotification(MSG_SWITCH_STATE, (CCObject*)(intptr_t)item->getSelectedIndex());
/* for testing removeAllObservers */
CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer1", NULL);
CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer2", NULL);
CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer3", NULL);
}
示例5: addChild
NotificationCenterTest::NotificationCenterTest()
: m_bShowImage(false)
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemFont* pBackItem = CCMenuItemFont::itemFromString("Back", this,
menu_selector(NotificationCenterTest::toExtensionsMainLayer));
pBackItem->setPosition(ccp(s.width - 50, 25));
CCMenu* pBackMenu = CCMenu::menuWithItems(pBackItem, NULL);
pBackMenu->setPosition( CCPointZero );
addChild(pBackMenu);
CCLabelTTF *label1 = CCLabelTTF::labelWithString("switch off", "Marker Felt", 26);
CCLabelTTF *label2 = CCLabelTTF::labelWithString("switch on", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2);
CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(NotificationCenterTest::toggleSwitch), item1, item2, NULL);
// turn on
item->setSelectedIndex(1);
CCMenu *menu = CCMenu::menuWithItems(item, NULL);
menu->setPosition(ccp(s.width/2+100, s.height/2));
addChild(menu);
CCMenu *menuConnect = CCMenu::menuWithItems(NULL);
menuConnect->setPosition(CCPointZero);
addChild(menuConnect);
for (int i = 1; i <= 3; i++)
{
Light* light = Light::lightWithFile("Images/Pea.png");
light->setTag(kTagLight+i);
light->setPosition(ccp(100, s.height/4*i));
addChild(light);
CCLabelTTF *label1 = CCLabelTTF::labelWithString("not connected", "Marker Felt", 26);
CCLabelTTF *label2 = CCLabelTTF::labelWithString("connected", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2);
CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(NotificationCenterTest::connectToSwitch), item1, item2, NULL);
item->setTag(kTagConnect+i);
item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50));
menuConnect->addChild(item, 0);
if (i == 2)
{
item->setSelectedIndex(1);
}
bool bConnected = item->getSelectedIndex() == 1 ? true : false;
light->setIsConnectToSwitch(bConnected);
}
CCNotificationCenter::sharedNotifCenter()->postNotification(MSG_SWITCH_STATE, (CCObject*)item->getSelectedIndex());
}
示例6: addToggleMenuItem
void BaseMenuLayer::addToggleMenuItem(CCArray* pArrayOfItems,SEL_MenuHandler selector,int select,...)
{
va_list args;
va_start(args, select);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, selector, NULL);
do{
const char* str = va_arg(args, const char*);
if(!str) break;
//CCLabelTTF *label = CCLabelTTF::create(str, "Arial", 24);
//CCMenuItemLabel *menuitem = CCMenuItemLabel::create(label);
CCLabelTTF* label = CCLabelTTF::create(str, "Arial", LARGE_FONT_SIZE);
CCSprite* s = CCSprite::create("Images/button1.png");
label->setPosition(ccp(s->getContentSize().width/2,s->getContentSize().height/2));
s->addChild(label);
CCMenuItemSprite* menuitem = CCMenuItemSprite::create(s, s,s,this, selector);
item->addSubItem(menuitem);
}while(true);
item->setSelectedIndex(select);
pArrayOfItems->addObject(item);
va_end(args);
}
示例7: addObjectiveLayer
void PauseLayer::addObjectiveLayer() {
objectiveLayer = CCLayer::create();
objectiveLayer->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5));
float scale = Utility::isIPad() ? 1 : 0.8;
CCLabelBMFont *labelObj = CCLabelBMFont::create("objectives", kFontChubby, 0);
labelObj->setPosition(ccp(winSize.width * 0, winSize.height * 0.45));
labelObj->setScale(scale);
objectiveLayer->addChild(labelObj, 2);
createButton("btnStats.png", 5, ccp(winSize.width * 0.3, winSize.height * 0.93));
int j = 0;
arrayForActive = CCArray::create();
for (int i = 1; i <= 41; i++) {
// int level = 40 - i;
if (Utility::getAchievementStatus(i) == 1) {
arrayForActive->insertObject(CCString::createWithFormat("%d", i), j);
j++;
if (j == 3) {
break;
}
}
}
for (int i = 0; i < arrayForActive->count(); i++) {
CCSprite *objective = CCSprite::createWithSpriteFrameName(kScrollBar);
objective->setPositionY(winSize.height * kScrollBarGap * i - winSize.height * 0.2);
CCString *string = (CCString*)arrayForActive->objectAtIndex(i);
int level = string->intValue();
CCString *obj_1 = (CCString*) Utility::objectiveDict()->valueForKey(CCString::createWithFormat("kAchievement_%d_0", level)->getCString());
CCString *obj_2 = (CCString*) Utility::objectiveDict()->valueForKey(CCString::createWithFormat("kAchievement_%d_1", level)->getCString());
createLabel(obj_1->getCString(), obj_2->getCString(), ccp(objective->getContentSize().width * 0.18, objective->getContentSize().height * 0.85), objective);
createSprite("iconTrophy.png", ccp(objective->getContentSize().width * 0.03, objective->getContentSize().height * 0.85), objective);
objectiveLayer->addChild(objective, 2);
}
addChild(objectiveLayer, 2);
arrayForActive->removeAllObjects();
arrayForActive->release();
soundOn = CCSprite::createWithSpriteFrameName("btnSoundOn.png");
menuItemSoundOn = CCMenuItemSprite::create(soundOn, soundOn, this, menu_selector(PauseLayer::soundsButtonTapped));
menuItemSoundOn->setTag(1);
soundOff = CCSprite::createWithSpriteFrameName("btnSoundOff.png");
menuItemSoundOff = CCMenuItemSprite::create(soundOff, soundOff, this, menu_selector(PauseLayer::soundsButtonTapped));
menuItemSoundOff->setTag(2);
CCMenuItemToggle *toggleSound = CCMenuItemToggle::createWithTarget(this, menu_selector(PauseLayer::soundsButtonTapped), menuItemSoundOn, menuItemSoundOff, NULL);
toggleSound->setSelectedIndex((CCUserDefault::sharedUserDefault()->getBoolForKey(kSoundsKey) ? 0 : 1));
menuSoundOff = CCMenu::create(toggleSound , NULL);
menuSoundOff->setPosition(ccp(winSize.width * 0.95, winSize.height * 0.92));
addChild(menuSoundOff, 2);
}
示例8: checkCard
void MarketScene::checkCard(int index)
{
CCMenu *pMenu = (CCMenu *)this->getChildByTag(TAG_MENU);
char szFileName[32] = { 0 };
for (int i = 0; i < CARD_COUNT; i++)
{
int tag = BTN_CARD + i;
CCMenuItemToggle *pToggle = (CCMenuItemToggle *)pMenu->getChildByTag(tag);
if (tag == index)
{
selectedIndex = index;
pToggle->setSelectedIndex(1);
pToggle->setEnabled(false);
sprintf(szFileName, s_pathCardInfo.m_strPath, i);
int price = getPrice(tag);
updateLabelAtlas(price, LabelAtlas_PRICE);
CCMenuItemImage *pMenuItem = (CCMenuItemImage *)pMenu->getChildByTag(BTN_BUY);
if (g_Control.cards[i] <= 0 && g_Control.m_nCoin > price)
{
pMenuItem->setEnabled(true);
}
else
{
pMenuItem->setEnabled(false);
}
}
else
{
pToggle->setSelectedIndex(0);
pToggle->setEnabled(true);
}
}
this->removeChildByTag(CARD_INFO);
CCSprite *pcdSprite = CCSprite::create(szFileName);
pcdSprite->setPosition(s_pathCardInfo.m_Position);
pcdSprite->setTag(CARD_INFO);
this->addChild(pcdSprite);
pcdSprite->runAction(CCSequence::create(CCSpawn::create(CCScaleTo::create(0.2f, 1.0f), CCFadeTo::create(0.2f, 255), NULL), NULL));
}
示例9: init
bool Options::init()
{
if (!CCLayer::init()) {
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite *sp = CCSprite::create(s_loading);
sp->setAnchorPoint(CCPointZero);
addChild(sp, 0, 1);
CCTexture2D *imageCache = CCTextureCache::sharedTextureCache()->addImage(s_menuTitle);
CCSprite *title = CCSprite::createWithTexture(imageCache, CCRectMake(0, 0, 134, 34));
title->setPosition(ccp(winSize.width/2, winSize.height - 60));
addChild(title);
CCMenuItemFont *menuTitle = CCMenuItemFont::create("Sound");
menuTitle->setFontName("Arial");
menuTitle->setFontSize(18);
menuTitle->setEnabled(false);
CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(26);
CCMenuItemToggle *toggle = CCMenuItemToggle::createWithTarget(this, menu_selector(Options::setOptions), CCMenuItemFont::create("On"),CCMenuItemFont::create("Off"), NULL);
int selectId = Config::sharedConfig()->getAudioState()? 0 : 1;
toggle->setSelectedIndex(selectId);
CCLabelBMFont *backLb = CCLabelBMFont::create("Go Back", s_font);
CCMenuItemLabel *goBack = CCMenuItemLabel::create(backLb, this, menu_selector(Options::goBack));
goBack->setScale(0.6);
CCActionInterval *fadeIn = CCFadeTo::create(1, 80);
CCActionInterval *fadeOut = CCFadeTo::create(1, 255);
CCEaseSineInOut *ease1 = CCEaseSineInOut::create(fadeIn);
CCEaseSineInOut *ease2 = CCEaseSineInOut::create(fadeOut);
CCFiniteTimeAction *seq = CCSequence::create(ease1, ease2, NULL);
// 这里也是,参数必须强转,否则NDK编译不过
goBack->runAction(CCRepeatForever::create((CCActionInterval*)seq));
CCMenu *menu = CCMenu::create( menuTitle, toggle, goBack, NULL);
menu->alignItemsInColumns(2,1);
addChild(menu);
CCPoint pos = goBack->getPosition();
pos.y -= 50;
goBack->setPosition(pos);
return true;
}
示例10: CCMenuItemToggle
CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems)
{
CCMenuItemToggle *pRet = new CCMenuItemToggle();
pRet->CCMenuItem::initWithTarget(target, selector);
pRet->m_pSubItems = CCArray::create();
pRet->m_pSubItems->retain();
for (unsigned int z=0; z < menuItems->count(); z++)
{
CCMenuItem* menuItem = (CCMenuItem*)menuItems->objectAtIndex(z);
pRet->m_pSubItems->addObject(menuItem);
}
pRet->m_uSelectedIndex = UINT_MAX;
pRet->setSelectedIndex(0);
return pRet;
}
示例11: initMenuToggle
void IOSStoreLayer::initMenuToggle()
{
//开宝箱按钮开关
CCMenuItemSprite* pNorItem = CCMenuItemSprite::create(
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_kaibaoxiang.png").c_str()),
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_kaibaoxiang.png").c_str()));
CCMenuItemSprite* pPreItem = CCMenuItemSprite::create(
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_kaibaoxiang_select.png").c_str()),
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_kaibaoxiang_select.png").c_str()));
CCMenuItemToggle* pToggle = CCMenuItemToggle::createWithTarget(this,
menu_selector(IOSStoreLayer::clickToggleCallBack),
pNorItem,
pPreItem, NULL);
pToggle->setTag(kaibaoxiang_toggle_tag);
pToggle->setPosition(ccp(m_pBg->getContentSize().width/2 - pToggle->getContentSize().width/2,
m_pBg->getContentSize().height/2 + pToggle->getContentSize().width/2 +25));
pToggle->setSelectedIndex(1);
m_pBgMenu->addChild(pToggle);
//购买星星按钮开关
pNorItem = CCMenuItemSprite::create(
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_goumaixingxing.png").c_str()),
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_goumaixingxing.png").c_str()));
pPreItem = CCMenuItemSprite::create(
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_goumaixingxing_select.png").c_str()),
CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_goumaixingxing_select.png").c_str()));
pToggle = CCMenuItemToggle::createWithTarget(this,
menu_selector(IOSStoreLayer::clickToggleCallBack),
pNorItem,
pPreItem, NULL);
pToggle->setTag(buystar_toggle_tag);
pToggle->setPosition(ccp(m_pBg->getContentSize().width/2 + pToggle->getContentSize().width/2,
m_pBg->getContentSize().height/2 + pToggle->getContentSize().width/2 + 25));
m_pBgMenu->addChild(pToggle);
}
示例12: SeriaUpdate
void SerialMager::SeriaUpdate()
{
if (!m_IsCom)
{
return;
}
int msg = 0;
msg = fetch_msg();
if (msg == 0 || m_curMsg == msg)
{
return;
}
m_curMsg = msg;
Ext_IsResetGG = true;
if (PostureAnalysisScene::m_bIsPlayVideo)
{
return;
}
if (m_curMsg == 2)
{
if (m_Delegate1)
{
m_Delegate1->Record(true);
}
if (m_Delegate2)
{
m_Delegate2->Record(true);
}
}
else if (m_curMsg == 3)
{
if (Ext_IsRecordBegin == true)
{
return;
}
Ext_IsRecordBegin = true;
Sleep(Ext_VideoSleep);
Ext_IsThreadOn = false;
if (m_Delegate1)
{
m_Delegate1->RecordOk();
}
if (m_Delegate2)
{
m_Delegate2->RecordOk();
}
//PostureAnalysisScene::m_bIsPlayVideo = true;
PostureAnalysisScene* pLayer = (PostureAnalysisScene*)CCDirector::sharedDirector()->getRunningScene()->getChildByTag(98);
CCMenuItemToggle* pToggle = (CCMenuItemToggle*)(pLayer->m_pMenu->getChildByTag(99));
pToggle->setSelectedIndex(1);
pLayer->CallbackPause(pToggle);
}
else if (m_curMsg == 4)
{
if (m_Delegate1)
{
m_Delegate1->Record(false);
}
if (m_Delegate2)
{
m_Delegate2->Record(false);
}
}
}