本文整理汇总了C++中CCMenuItemToggle::setTag方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemToggle::setTag方法的具体用法?C++ CCMenuItemToggle::setTag怎么用?C++ CCMenuItemToggle::setTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemToggle
的用法示例。
在下文中一共展示了CCMenuItemToggle::setTag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addButton
bool PoptipLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, CCPoint &pos, int tag/* = 0*/)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
// 创建图片菜单按钮
CCMenuItemImage *normal = CCMenuItemImage::create(normalImage, normalImage);
CCMenuItemImage *checked = CCMenuItemImage::create(selectedImage, selectedImage);
//创建开关按钮选项,并设置回调函数
CCMenuItemToggle *toggle = CCMenuItemToggle::createWithTarget(this,
menu_selector(PoptipLayer::buttonCallback),
normal,
checked,
NULL
);
toggle->setTag(tag);
toggle->setPosition(pCenter);
toggle->setPosition(pos);
getMenuButton()->addChild(toggle);
return true;
}
示例2: 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);
}
示例3: 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());
}
示例4: 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);
}
示例5: initButton
void MarketScene::initButton()
{
CCMenuItemImage *pMenuItem = CCMenuItemImage::create(s_pMenuItemBack.charMapFile, s_pMenuItemBack.charMapFilePress, this, menu_selector(MarketScene::buttonCallback));
if (NULL != pMenuItem)
{
pMenuItem->setAnchorPoint(ccp(1,1));
pMenuItem->setPosition(SCREEN);
pMenuItem->setTag(BTN_CLOSE);
}
CCMenu *pMenu = CCMenu::create(pMenuItem, NULL);
if (NULL != pMenu)
{
pMenu->setPosition(CCPointZero);
addChild(pMenu);
pMenu->setTag(TAG_MENU);
}
pMenuItem = CCMenuItemImage::create(s_pMenuItemBuy.charMapFile, s_pMenuItemBuy.charMapFilePress, s_pBuyDisable, this, menu_selector(MarketScene::buttonCallback));
pMenuItem->setAnchorPoint(ccp(0.5f, 0.5f));
pMenuItem->setPosition(ccp(CENTER.x, 120));
pMenuItem->setTag(BTN_BUY);
pMenu->addChild(pMenuItem);
char szFileName[32] = { 0 };
char szFileName2[32] = { 0 };
char szFileName3[32] = { 0 };
for (int i = 0; i < CARD_COUNT; i++)
{
sprintf(szFileName, s_pathCard.charMapFile, i);
sprintf(szFileName2, s_pathCard.charMapFilePress, i);
sprintf(szFileName3, s_pathCardDisable, i);
CCMenuItemImage *pItem0 = CCMenuItemImage::create(szFileName, szFileName2, szFileName3);
CCMenuItemImage *pItem1 = CCMenuItemImage::create(szFileName2, szFileName);
CCMenuItemToggle *pToggle = CCMenuItemToggle::createWithTarget(this, menu_selector(MarketScene::buttonCallback), pItem0, pItem1, NULL);
pToggle->setPosition(ccp(120 * i + s_pathCard.m_Position.x, s_pathCard.m_Position.y));
pToggle->setTag(BTN_CARD + i);
if (g_Control.cards[i] > 0)
{
CCSprite *sprite = CCSprite::create(s_pathCardbuy.m_strPath);
sprite->setPosition(s_pathCardbuy.m_Position);
pToggle->addChild(sprite, TAG_CARD_BUY, TAG_CARD_BUY);
}
pMenu->addChild(pToggle);
}
checkCard(BTN_CARD);
}
示例6: init
bool StartScene::init(){
bool success = false;
do{
CCSprite* bg = CCSprite::create("startBg.jpg");
CC_BREAK_IF(!bg);
SETANCHPOS(bg,0,0,0,0);
addChild(bg);
//初始化用户数据
GameData::getInstance();
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("start.plist","start.png");
//游戏菜单
CCMenu* menu = CCMenu::create();
CC_BREAK_IF(!menu);
SETANCHPOS(menu,650,130,0,0);
addChild(menu);
CCMenuItemSprite* start = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("start.png"),
CCSprite::createWithSpriteFrameName("start.png"),
this,menu_selector(StartScene::btnCallback));
CC_BREAK_IF(!start);
start->setTag(1);
menu->addChild(start);
CCMenuItemSprite* shop = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("shop.png"),
CCSprite::createWithSpriteFrameName("shop.png"),
this,menu_selector(StartScene::btnCallback));
CC_BREAK_IF(!shop);
shop->setTag(2);
menu->addChild(shop);
CCMenuItemSprite* more = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("more.png"),
CCSprite::createWithSpriteFrameName("more.png"),
this,menu_selector(StartScene::btnCallback));
CC_BREAK_IF(!more);
more->setTag(3);
menu->addChild(more);
menu->alignItemsVertically();
//标题
CCSprite* titleBg = CCSprite::createWithSpriteFrameName("name_bg.png");
CC_BREAK_IF(!titleBg);
SETANCHPOS(titleBg,500,250,0,0);
addChild(titleBg);
CCSprite* title = CCSprite::createWithSpriteFrameName("name.png");
CC_BREAK_IF(!title);
SETANCHPOS(title,500,250,0,0);
addChild(title);
//开关按钮
CCMenu* sound = CCMenu::create();
CC_BREAK_IF(!sound);
SETANCHPOS(sound,50,50,0,0);
addChild(sound);
soundOn = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("sound_off.png"),
CCSprite::createWithSpriteFrameName("sound_off.png"),
this,NULL);
soundOff = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("sound_on.png"),
CCSprite::createWithSpriteFrameName("sound_on.png"),
this,NULL);
CCMenuItemToggle* toggle = CCMenuItemToggle::createWithTarget(this,menu_selector(StartScene::btnCallback),soundOff,soundOn,NULL);
toggle->setTag(4);
sound->addChild(toggle);
//SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("game.ogg"));
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("game.ogg",true);
success = true;
}while(false);
return success;
}