本文整理汇总了C++中CCMenuItemToggle::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemToggle::setPosition方法的具体用法?C++ CCMenuItemToggle::setPosition怎么用?C++ CCMenuItemToggle::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemToggle
的用法示例。
在下文中一共展示了CCMenuItemToggle::setPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: 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);
}
示例4: 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());
}
示例5: 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);
}
示例6: 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);
}
示例7:
bool Recipe15::init()
{
if ( !CCLayerGradient::initWithColor(ccc4(170,145,25,255),ccc4(17,220,160,255),ccp(0.0f,1.0f)))
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
m_points = 0;
m_actionType = 1;
this->setTouchMode(kCCTouchesOneByOne);
this->setTouchEnabled(true);
CCSprite *player = CCSprite::create("monkey01.png");
player->setTag(1);
player->setPosition(ccp(player->getContentSize().height*3/2, visibleSize.width/2));
player->setOpacity(210);
this->addChild(player);
this->schedule(schedule_selector(Recipe15::gameLogic),3.0);
this->scheduleUpdate();
CCMenuItemImage* pCloseItem = CCMenuItemImage::create(
"button_close.png",
"button_close_pressed.png",
this,
menu_selector(Recipe15::menuCloseCallback));
pCloseItem->setPosition(ccp(
visibleSize.width - pCloseItem->getContentSize().width/2,
pCloseItem->getContentSize().height/2));
//CCMenu* pMenu = CCMenu::create(pCloseItem,NULL);
//pMenu->setPosition(CCPointZero);
// this->addChild(pMenu);
CCSprite* item1 = CCSprite::create("button_close.png");
CCSprite* item2 = CCSprite::create("button_close.png");
item2->setColor(ccc3(102,102,255));
CCMenuItemSprite* pCloseItem2 =
CCMenuItemSprite::create(item1,item2,this,
menu_selector(Recipe15::menuCloseCallback));
pCloseItem2->setPosition(ccp(
visibleSize.width -pCloseItem->getContentSize().width*3/2,
pCloseItem->getContentSize().height/2));
CCMenu* pMenu2 = CCMenu::create(pCloseItem,pCloseItem2,NULL);
pMenu2->setPosition(CCPointZero);
this->addChild(pMenu2);
CCMenuItemImage* menuItemOff = CCMenuItemImage::create(
"button_check_off.png",
"button_check_off_pressed.png",NULL);
CCMenuItemImage* menuItemOn = CCMenuItemImage::create(
"button_check_on.png",
"button_check_on_pressed.png",NULL);
CCMenuItemToggle* toggleItem =
CCMenuItemToggle::createWithTarget(this,menu_selector(Recipe15::changeMode),menuItemOff,menuItemOn,NULL);
toggleItem->setPosition(ccp(
toggleItem->getContentSize().width/2,
visibleSize.height - toggleItem->getContentSize().height/2));
CCMenu* toggleMenu = CCMenu::create(toggleItem,NULL);
toggleMenu->setPosition(0,0);
toggleMenu->setTag(3);
this->addChild(toggleMenu);
CCLabelTTF *scoreLabel = CCLabelTTF::create("SCORE","aria",48);
scoreLabel->setPosition(ccp(visibleSize.width/2,visibleSize.height - scoreLabel->getContentSize().height/2));
scoreLabel->setTag(10);
this->addChild(scoreLabel);
CCLabelTTF* pointsLabel = CCLabelTTF::create("0","arial",48);
pointsLabel->setPosition(ccp(scoreLabel->getPositionX() + scoreLabel->getContentSize().width,
visibleSize.height - pointsLabel->getContentSize().height/2));
pointsLabel->setTag(11);
this->addChild(pointsLabel);
return true;
}
示例8: okCallback
void HelloWorld::okCallback(CCObject* pSender)
{
if(!m_bg)
{
m_runLayer = CCLayer::create();
this->addChild(m_runLayer);
int dirSel = m_dirSelItem->getSelectedIndex();
switch (dirSel)
{
case 0:
m_bg = ScrollingBackground::create(SD_RIGHT_TO_LEFT);
m_direction = SD_RIGHT_TO_LEFT;
break;
case 1:
m_bg = ScrollingBackground::create(SD_LEFT_TO_RIGHT);
m_direction = SD_LEFT_TO_RIGHT;
break;
case 2:
m_bg = ScrollingBackground::create(SD_TOP_TO_BOTTOM);
m_direction = SD_TOP_TO_BOTTOM;
break;
case 3:
m_bg = ScrollingBackground::create(SD_BOTTOM_TO_TOP);
m_direction = SD_BOTTOM_TO_TOP;
break;
default:
break;
}
m_runLayer->addChild(m_bg,1);
for (int i = 1; i < 5; i++)
{
addBgSprite(i);
}
//当有一个背景精灵彻底离开屏幕的时候的消息
if(m_modeSelItem->getSelectedIndex()==0)
m_bg->setBgChangeEventListener(this,bgSpriteChangeEvent(HelloWorld::loopBgChangeCallback)); //循环模式
else
m_bg->setBgChangeEventListener(this,bgSpriteChangeEvent(HelloWorld::dropBgChangeCallback)); //丢弃模式
//当背景精灵移动时候的消息
m_bg->setBgMoveEventListener(this,bgSpriteMoveEvent(HelloWorld::bgMoveCallback));
m_velocity = 300.0f;
m_bgSprite = m_bg->getCurBgSprite();
m_bg->beginContinuousScroll(m_velocity);
//一个跟随背景移动的物体
m_pItem = CCSprite::create("item.png");
m_pItem->setAnchorPoint(ccp(0.5f,0.5f));
m_pItem->setPosition(ccp(0.0f,0.0f));
m_runLayer->addChild(m_pItem,2);
//pItem锚点一直都是(0.5,0.5),坐标一直是(0.0,0.0),注意看当画面切换的时候他会出现在哪里
//背景精灵精灵的锚点不同,会影响pItem的位置
m_pItem->setPosition(m_bg->getCurBgSprite()->getPosition());
/*下面的是一些菜单的设置,不看也可以*/
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//返回按钮
CCMenuItemFont* back = CCMenuItemFont::create("back",this,menu_selector(HelloWorld::backCallback));
back->setAnchorPoint(ccp(1.0f,1.0f));
back->setPosition(ccp(visibleSize.width/2.0f,visibleSize.height/2.0f));
//设置相反速度的按钮
CCMenuItemFont* reverse = CCMenuItemFont::create("reverse",this,menu_selector(HelloWorld::reverseCallback));
//暂停
CCMenuItemToggle* pause = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::pauseCallback),
CCMenuItemFont::create("pause"),
CCMenuItemFont::create("resume"),
NULL);
pause->setPosition(ccp(0.0f,50.0f));
//上一个画面
CCMenuItemImage* lastBg = CCMenuItemImage::create("lastBgNor.png","lastBgCli.png",0,this,menu_selector(HelloWorld::nextBgCallback));
lastBg->setTag(0);
lastBg->setAnchorPoint(ccp(0.0f,0.5f));
lastBg->setPosition(ccp(-visibleSize.width/2.0f,0.0f));
//下一个画面
CCMenuItemImage* nextBg = CCMenuItemImage::create("NextBgNor.png","NextBgCli.png",0,this,menu_selector(HelloWorld::nextBgCallback));
nextBg->setTag(1);
nextBg->setAnchorPoint(ccp(1.0f,0.5f));
nextBg->setPosition(ccp(visibleSize.width/2.0f,0.0f));
//增加背景精灵
CCMenuItemFont* add = CCMenuItemFont::create("add background",this,menu_selector(HelloWorld::addBgSpriteCallback));
add->setPosition(ccp(0.0f,-50.0f));
CCMenu* pMenu = CCMenu::create(pause,reverse,add,lastBg,nextBg,back,NULL);
//.........这里部分代码省略.........