本文整理汇总了C++中CCMenu::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenu::addChild方法的具体用法?C++ CCMenu::addChild怎么用?C++ CCMenu::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenu
的用法示例。
在下文中一共展示了CCMenu::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initWithController
bool GameUI::initWithController(GameScene* controller, int chapter, int level) {
{
CCMenu* gameplay = CCMenu::node();
{
CCSprite* up = CCSprite::spriteWithSpriteFrameName("reset_button.png");
CCSprite* down = CCSprite::spriteWithSpriteFrameName("reset_button_pressed.png");
CCMenuItemSprite* restartButton = CCMenuItemSprite::itemFromNormalSprite(up, down, controller, menu_selector(GameScene::restartGame));
gameplay->addChild(restartButton, 0);
}
{
CCSprite* up = CCSprite::spriteWithSpriteFrameName("pause_button.png");
CCSprite* down = CCSprite::spriteWithSpriteFrameName("pause_button_pressed.png");
CCMenuItemSprite* pauseButton = CCMenuItemSprite::itemFromNormalSprite(up, down, controller, menu_selector(GameScene::pauseGame));
gameplay->addChild(pauseButton, 0);
}
{
BoostBar* boostBar = BoostBar::node();
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
boostBar->setPosition(ccp(110, screenSize.height - 20));
this->addChild(boostBar, boostBar->getZOrder(), TAG_BOOST);
}
{
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
String levelString = String::withFormat("%d - %d", chapter + 1, level + 1);
CCLabelBNFont* levelLabel = CCLabelBNFont::labelWithString(levelString.c_str(), "soupofjustice_24_white.fnt");
levelLabel->setPosition(ccp(screenSize.width - 30, -10));
addChild(levelLabel);
CCDelayTime* delayIn = CCDelayTime::actionWithDuration(2);
CCMoveBy* moveUp = CCMoveBy::actionWithDuration(0.4, ccp(0, 25));
CCEaseBackOut* moveUpEase = CCEaseBackOut::actionWithAction(moveUp);
CCFiniteTimeAction* sequence = CCSequence::actions(delayIn, moveUpEase, 0);
levelLabel->runAction(sequence);
}
{
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
gameplay->setPosition(ccp(screenSize.width - 50, screenSize.height - 20));
gameplay->alignItemsHorizontallyWithPadding(-10);
this->addChild(gameplay);
}
}
return true;
}
示例2: 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);
}
示例3: onLoadScene
//-------------------------------------------------------------------------
// 其他逻辑初始化
void CShopTestScene::onLoadScene()
{
setAutoRemoveUnusedTexture( true );
// 根窗口,用来挂载显示物件
{
m_pRootWindow = FKCW_UIWidget_WidgetWindow::create();
m_pRootWindow->setMultiTouchEnabled(true);
this->addChild(m_pRootWindow);
}
// 返回按钮
{
CCMenu *pMenu = CCMenu::create();
pMenu->setPosition(CCPointZero);
addChild(pMenu);
CCMenuItemImage* pBtn = CCMenuItemImage::create();
CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("back_button_normal_e.png");
pBtn->setNormalSpriteFrame(pFrame);
pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("back_button_touch_e.png");
pBtn->setSelectedSpriteFrame(pFrame);
pBtn->setTarget(this, menu_selector(CShopTestScene::onClick));
pBtn->setPosition(SCREEN_CENTER_POS + ccp(0,400));
pMenu->addChild(pBtn);
}
}
示例4: init
bool testEffect::init(){
if ( !CCLayer::init() ){return false;}
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("0.GeneralPart.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("MikuFight.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("SheldonFight.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("IronManFight.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LichKingFight.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("BladeMasterFight.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("FightGeneral.plist");
ASBotFightLayer* aaa = ASBotFightLayer::createAsFightLayer(2, 4,true,1000,1,10000,6,10000,10);
aaa->setPosition(CCPointZero);
addChild(aaa,9999,9999);
CCMenu* menu = CCMenu::create();
for (int i = 1; i < 7 ; i++) {
string tmp = "card_" + int2string(i) + ".png";
CCSprite* repeatSprite = CCSprite::createWithSpriteFrameName(tmp.c_str());
CCMenuItemSprite* repeat = CCMenuItemSprite::create(repeatSprite,repeatSprite,this,menu_selector(testEffect::Repeat));
repeat->setScale(0.45);
repeat->setPosition(ccp(size.width/7 + size.width*(i-1)/7,size.height/8));
repeat->setTag(i);
menu->addChild(repeat);
}
menu->setPosition(CCPointZero);
addChild(menu,10000);
return true;
}
示例5: init
// on "init" you need to initialize your instance
bool MissionLayer::init() {
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() ) {
return false;
}
this->setKeypadEnabled(true);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* title = CCLabelTTF::create("Mission", "Arial", 24);
title->setPosition( ccp(size.width / 2, size.height - 20));
this->addChild(title, 1);
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"b1.png",
"b2.png",
this,
menu_selector(MissionLayer::menuBackCallback) );
pCloseItem->setPosition( ccp(pCloseItem->getContentSize().width / 2 , 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
// add next menu
CCMenuItemImage *pNextItem = CCMenuItemImage::create(
"f1.png",
"f2.png",
this,
menu_selector(MissionLayer::menuNextCallback) );
pNextItem->setPosition( ccp(size.width - pNextItem->getContentSize().width / 2, 20) );
// create menu, it's an autorelease object
CCMenu* pNextMenu = CCMenu::create(pNextItem, NULL);
pNextMenu->setPosition( CCPointZero );
this->addChild(pNextMenu, 1);
float step = 35;
float yPos = 0;
for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
char buf[64];
sprintf(buf, s_EventMenuItem[i].id.c_str(), missionid);
CCLabelTTF* label = CCLabelTTF::create(buf, "Arial", 24);
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MissionLayer::eventMenuCallback));
pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
yPos = size.height - step*i - 100;
pMenuItem->setPosition( ccp(size.width / 2, yPos));
}
return true;
}
示例6: init
bool BoxMenu::init()
{
if(!CCLayer::init())
{
return false;
}
CCMenu *teamMenu;
CCMenuItemFont::setFontName("΢ÈíÑźÚ");
CCMenuItemFont::setFontSize(20);
teamMenu = getBoxMenu();
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
string gameTitle = GameTitleString;
GBKToUTF8(gameTitle,"gbk","utf-8");
CCMenuItemFont::setFontSize(26);
CCMenuItemFont *titleItem = CCMenuItemFont::create(gameTitle.c_str(), this, menu_selector(BoxMenu::scoreSort));
titleItem->setColor(ccc3(0xc3, 0xa8, 0x91));
titleItem->setPosition(CCPointMake(0, winSize.height/2 - 30));
teamMenu->addChild(titleItem);
CCSprite *backgroudSprite = CCSprite::create(mainBackgroudFile);
backgroudSprite->setPosition(CCPointMake(winSize.width/2, winSize.height/2));
addChild(teamMenu, 0);
addChild(backgroudSprite, -2);
return true;
}
示例7: tableCellAtIndex
CCTableViewCell* MainLayerZhuangBeiBody::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
CCString *string = CCString::createWithFormat("%d", idx);
CCTableViewCell *cell = NULL; //table->dequeueCell();
if (cell == NULL)
{
cell = new CCTableViewCell();
cell->autorelease();
}
else
{
cell->removeAllChildren();
}
//
CCMenuItemImage *itemImage = CCMenuItemImage::create(
itemFiles[idx].c_str()
,itemFiles_select[idx].c_str()
, this, SEL_MenuHandler(&MainLayerZhuangBeiBody::menuItemClicked));
CCMenu* menu = CCMenu::create();
cell->addChild(menu, 0, TAG_MENU);
menu->setPosition(CCPointZero);
menu->addChild(itemImage, 0, idx);
itemImage->setPosition(ccp(itemImage->getContentSize().width/2, itemImage->getContentSize().height/2));
return cell;
}
示例8: createListView
void NewsScene::createListView()
{
// CCSize size = CCSize(750, 400);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLayerColor * fundo = CCLayerColor::create(ccc4(255, 255, 255, 255), size.width, size.height);
fundo->setAnchorPoint(ccp(0,0));
fundo->setPosition(ccp(0, 0));
this->addChild(fundo,10);
// CCLayerColor * header = CCLayerColor::create(ccc4(200, 200, 200, 255), size.width, 80);
// header->setAnchorPoint(ccp(0,0));
// header->setPosition(ccp(0, size.height -80));
// fundo->addChild(header);
CCSprite *sprHeader;
sprHeader = CCSprite::create("Header_Blue.png");
sprHeader->setAnchorPoint(ccp(0,0));
sprHeader->setScale(1);
sprHeader->setPosition(ccp(0, size.height -90));
this->addChild(sprHeader,100);
CCSprite *sprTitle;
sprTitle = CCSprite::create("tit_informacoes.png");
sprTitle->setAnchorPoint(ccp(0,0));
sprTitle->setScale(1);
sprTitle->setPosition(ccp(110, size.height -50));
this->addChild(sprTitle,101);
CCMenu* menu = CCMenu::create();
CCSprite *spriteDefault = CCSprite::create("Seta1.png");
CCSprite *spriteSelected = CCSprite::create("Seta2.png");
CCMenuItemSprite *item = CCMenuItemSprite::create(spriteDefault, spriteSelected, this, menu_selector(NewsScene::btnBack));
item->setAnchorPoint(ccp(0, 0));
item->setPosition(ccp(0, size.height -90));
menu->addChild(item, 0, 100);
menu->setPosition(ccp(10,30));
menu->setAnchorPoint(ccp(0,0));
this->addChild(menu,102);
list = CCListView::create(CCListViewModeVertical);
list = cocos2d::extension::CCListView::create(CCListViewModeVertical);
list->setDelegate(this);
list->setContentSize(CCSize(size.width, size.height-70));
list->setAnchorPoint(ccp(0,0));
list->setPosition(ccp(0, 0));
list->setColor(ccc3(50, 50, 50));
list->setSeparatorStyle(CCListViewCellSeparatorStyleNone);
fundo->addChild(list);
this->loading = new AnimatedSprite("loader_einstein1.png");
this->loading->addAnimation(AnimatedSprite::animationWithFile("loader_einstein", 24, 0.030f), "anim");//frame_count
this->addChild(this->loading,999);
this->loading->runAnimation("anim",true, true);
this->loading->setAnchorPoint(ccp(0.5f, 0.5f));
this->loading->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2, CCDirector::sharedDirector()->getWinSize().height/2 - 30));
this->loading->setVisible(true);
}
示例9: CCPoint
LayerLevels::LayerLevels()
{
CCPoint* offset = new CCPoint(180, 180);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
CCMenuItemSprite* level = CCMenuItemSprite::create(
CCSprite::createWithSpriteFrameName("btn_level1.png"),
CCSprite::createWithSpriteFrameName("btn_level2.png"),
this, menu_selector(LayerLevels::click_level));
CCMenu* menu = CCMenu::createWithItem(level);
menu->setPosition(CCDirector::sharedDirector()->convertToUI(
ccp(offset->x + 200* i, offset->y + 85 * j)));
this->addChild(menu);
char str[64] = {0};
sprintf(str, "%d", (j * 4 + i + 1));
CCMenuItem* menuitem = new CCMenuItem();
CCLabelTTF* text = CCLabelTTF::create(
str, "Arial", 22);
text->setColor(ccBLACK);
menuitem->addChild(text);
menu->addChild(menuitem);
}
}
}
示例10: addChild
HttpClientTest::HttpClientTest()
: m_labelStatusCode(NULL)
{
#if 0
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::create("Http Request Test", "Arial", 28);
label->setPosition(ccp(winSize.width / 2, winSize.height - 50));
addChild(label, 0);
CCMenu *menuRequest = CCMenu::create();
menuRequest->setPosition(CCPointZero);
addChild(menuRequest);
// Get
CCLabelTTF *labelGet = CCLabelTTF::create("Test Get", "Arial", 22);
CCMenuItemLabel *itemGet = CCMenuItemLabel::create(labelGet, this, menu_selector(HttpClientTest::onMenuGetTestClicked));
itemGet->setPosition(ccp(winSize.width / 2, winSize.height - 100));
menuRequest->addChild(itemGet);
// Post
CCLabelTTF *labelPost = CCLabelTTF::create("Test Post", "Arial", 22);
CCMenuItemLabel *itemPost = CCMenuItemLabel::create(labelPost, this, menu_selector(HttpClientTest::onMenuPostTestClicked));
itemPost->setPosition(ccp(winSize.width / 2, winSize.height - 150));
menuRequest->addChild(itemPost);
// Post Binary
CCLabelTTF *labelPostBinary = CCLabelTTF::create("Test Post Binary", "Arial", 22);
CCMenuItemLabel *itemPostBinary = CCMenuItemLabel::create(labelPostBinary, this, menu_selector(HttpClientTest::onMenuPostBinaryTestClicked));
itemPostBinary->setPosition(ccp(winSize.width / 2, winSize.height - 200));
menuRequest->addChild(itemPostBinary);
// Response Code Label
m_labelStatusCode = CCLabelTTF::create("HTTP Status Code", "Marker Felt", 20);
m_labelStatusCode->setPosition(ccp(winSize.width / 2, winSize.height - 250));
addChild(m_labelStatusCode);
// Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(HttpClientTest::toExtensionsMainLayer));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero);
addChild(menuBack);
#endif
}
示例11: init
bool GameReviveLayer::init()
{
if(!CCLayer::init())
return false;
CCSize size = ToolsFun::sharedTools()->getSceneSize();
CCSprite *bkgSprite = CCSprite::create("DayReward/bkg.png");
this->addChild(bkgSprite, 3);
bkgSprite->setPosition(size / 2);
CCMenu *menu = CCMenu::create();
menu->setPosition(CCPointZero);
bkgSprite->addChild(menu, 1);
CCSprite *closeNor = CCSprite::create("ui/shared/closeTipNml.png");
CCSprite *closeSel = CCSprite::create("ui/shared/closeTipNml.png");
closeSel->setColor(ccc3(80, 80, 80));
CCMenuItemSprite *closeItem = CCMenuItemSprite::create(closeNor, closeSel, this, menu_selector(GameReviveLayer::close));
closeItem->setPosition(ccp(bkgSprite->getContentSize().width * 5 / 6, bkgSprite->getContentSize().height * 6 / 7));
menu->addChild(closeItem, 144);
CCSprite *getNor = CCSprite::create("ui/shared/continueGame.png");
CCSprite *getSel = CCSprite::create("ui/shared/continueGame.png");
getSel->setColor(ccc3(80, 80, 80));
CCMenuItemSprite *getItem = CCMenuItemSprite::create(getNor, getSel, this, menu_selector(GameReviveLayer::purchase));
getItem->setPosition(ccp(bkgSprite->getContentSize().width / 2, 10*gScaleY));
menu->addChild(getItem, 144);
CCSprite *tip1 = CCSprite::create("DayReward/advanced.png");
bkgSprite->addChild(tip1);
tip1->setPosition(ccp(bkgSprite->getContentSize().width/2,bkgSprite->getContentSize().height/2-50*gScaleY));
/*
char buf[32];
sprintf(buf,"%d",6);
CCLabelTTF *label = CCLabelTTF::create(buf,"΢ÈíÑźÚ",38);
getItem->addChild(label);
label->setScale(0.6f);
label->setColor(ccc3(220 ,220 ,220));
label->setPosition(ccp(bkgSprite->getPositionX()/2,bkgSprite->getPositionY()/2 ));*/
registerNDK();
return true;
}
示例12: gameOver
void GameScene::gameOver(){
removeChild(getChildByTag(99),true);
unschedule(schedule_selector(GameScene::bgMove));
CCLayerColor* ol = CCLayerColor::create(ccc4(0,0,0,150));
addChild(ol,20);
CCSprite* overBg = CCSprite::create("over_bg.png");
SETANCHPOS(overBg,425,240,0.5,0.5);
addChild(overBg,21);
CCMenu* menu = CCMenu::create();
SETANCHPOS(menu,425,240,0.5,0.5);
addChild(menu,21);
CCMenuItemSprite* retry = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("retry.png"),
CCSprite::createWithSpriteFrameName("retry.png"),this,menu_selector(GameScene::btnCallback));
SETANCHPOS(retry,-180,-110,0,0);
retry->setTag(3);
menu->addChild(retry);
CCMenuItemSprite* play = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("play.png"),
CCSprite::createWithSpriteFrameName("play.png"),this,menu_selector(GameScene::btnCallback));
SETANCHPOS(play,80,-110,0,0);
play->setTag(4);
menu->addChild(play);
CCSprite* dis = CCSprite::createWithSpriteFrameName("distance.png");
SETANCHPOS(dis,350,300,0.5,0.5);
addChild(dis,21);
char v[20];
sprintf(v,"%d",GameData::getDistance());
CCLabelAtlas* disText =CCLabelAtlas::create(v,"num/num_yellow.png",28,40,'0');
SETANCHPOS(disText,430,280,0,0);
addChild(disText,21);
CCSprite* best = CCSprite::createWithSpriteFrameName("best.png");
SETANCHPOS(best,350,250,0.5,0.5);
addChild(best,21);
sprintf(v,"%d",GameData::getBest() > GameData::getDistance() ? GameData::getBest() : GameData::getDistance());
CCLabelAtlas* bestText =CCLabelAtlas::create(v,"num/num_red.png",28,40,'0');
SETANCHPOS(bestText,410,230,0,0);
addChild(bestText,21);
}
示例13: init
// on "init" you need to initialize your instance
bool AchievementLayer::init() {
if (!CCLayerColor::initWithColor(ccc4(100, 255, 255, 255)))
return false;
_achievementAchievementsLayer = NULL;
//adding the background
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
cocos2d::CCSprite* backgroundArt = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("menuBackground.png"));
float bgScale = winSize.height / backgroundArt->getContentSize().height;
backgroundArt->setScale(bgScale);
float diff = winSize.width - backgroundArt->getContentSize().width * bgScale;
float x = backgroundArt->getContentSize().width / 2 * bgScale + diff / 2;
float y = backgroundArt->getContentSize().height / 2 * bgScale;
backgroundArt->setPosition(ccp(x, y));
addChild(backgroundArt);
float scaleMult = Model::getInstance()->getGUIElementScaleMultiplicator();
//back button
int buttonHeight = 66 * scaleMult;
int buttonLength = 66 * scaleMult;
CCMenu* backButtonmenu = CCMenu::create();
CCMenuItemSprite *backButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("return0.png"),
CCSprite::createWithSpriteFrameName("return1.png"), (CCObject*) this, menu_selector(AchievementLayer::backTouched));
backButton->setScaleX(buttonLength / backButton->getContentSize().width);
backButton->setScaleY(buttonHeight / backButton->getContentSize().height);
backButtonmenu->addChild(backButton);
CCMenuItemSprite *toggleModeButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("toggleGUI1.png"),
CCSprite::createWithSpriteFrameName("toggleGUI2.png"), (CCObject*) this, menu_selector(AchievementLayer::toggleModeTouched));
toggleModeButton->setScaleX(buttonLength / toggleModeButton->getContentSize().width);
toggleModeButton->setScaleY(buttonHeight / toggleModeButton->getContentSize().height);
backButtonmenu->addChild(toggleModeButton);
float padding = 10 * scaleMult;
backButtonmenu->alignItemsVerticallyWithPadding(padding);
addChild(backButtonmenu);
backButtonmenu->setPosition(CCPoint(winSize.width - buttonLength / 2, winSize.height - (buttonHeight * 2.0f + padding) / 2));
float offsetDown = ViewTools::addVersionAndCreditInfo(this, scaleMult);
ViewTools::addIdleUnitTo(this, offsetDown);
return true;
}
示例14: 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);
}
示例15: init
bool MainScene::init()
{
CCSize winSize = Director::getInstance()->getVisibleSize();
if (!CCLayer::init())
{
return false;
}
auto BackGround = Sprite::create("backg.png");
BackGround->setPosition(ccp(winSize.width / 2, winSize.height / 2)); //위치지정
this->addChild(BackGround);
CCMenu *MenuMain = CCMenu::create(NULL); //메뉴생성
CCMenu *MenuMain1 = CCMenu::create(NULL); //메뉴생성
CCMenu *MenuMain2 = CCMenu::create(NULL); //메뉴생성
//메뉴아이템 추가
CCMenuItem *item1 = CCMenuItemImage::create("start.png",
"start.png",
this,
menu_selector(MainScene::menuCloseCallback));
CCMenuItem *item2 = CCMenuItemImage::create("rank.png",
"rank.png",
this,
menu_selector(MainScene::RankCloseCallback));
CCMenuItem *item3 = CCMenuItemImage::create("create.png",
"create.png",
this,
menu_selector(MainScene::CreaterMenuCallback));
MenuMain->addChild(item1, 1); //메뉴에 아이템 붙이기
MenuMain1->addChild(item2, 2);
MenuMain2->addChild(item3, 3);
MenuMain->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 20));
MenuMain1->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 90));
MenuMain2->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 160));
this->addChild(MenuMain, 1);
this->addChild(MenuMain1, 2);
this->addChild(MenuMain2, 3);//메뉴를 레이어에 추가
CCUserDefault* user = CCUserDefault::sharedUserDefault();
int SaveSw = CCUserDefault::sharedUserDefault()->getIntegerForKey("SaveMake");
if (SaveSw == 0){
user->setIntegerForKey("SaveMake", 1);
user->setIntegerForKey("Rank1", 0);
user->setIntegerForKey("Rank2", 0);
user->setIntegerForKey("Rank3", 0);
user->setIntegerForKey("Rank4", 0);
user->setIntegerForKey("Rank5", 0);
}
return true;
}