本文整理汇总了C++中CCMenuItem::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItem::addChild方法的具体用法?C++ CCMenuItem::addChild怎么用?C++ CCMenuItem::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItem
的用法示例。
在下文中一共展示了CCMenuItem::addChild方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
}
示例2: init
bool CChooseLetterWindow::init()
{
m_Back = Sprite::create("choose_letter.png");
m_Back->setPosition(600,384);
m_Back->setVisible(false);
addChild(m_Back);
std::vector<char> m_Letters;
m_Letters.resize(26);
m_Letters[0] = 'a'; m_Letters[1] = 'b'; m_Letters[2] = 'c'; m_Letters[3] = 'd'; m_Letters[4] = 'e'; m_Letters[5] = 'f'; m_Letters[6] = 'g';
m_Letters[7] = 'h'; m_Letters[8] = 'i'; m_Letters[9] = 'j'; m_Letters[10] = 'k'; m_Letters[11] = 'l'; m_Letters[12] = 'm'; m_Letters[13] = 'n';
m_Letters[14] = 'o'; m_Letters[15] = 'p'; m_Letters[16] = 'q'; m_Letters[17] = 'r'; m_Letters[18] = 's'; m_Letters[19] = 't'; m_Letters[20] = 'u';
m_Letters[21] = 'v'; m_Letters[22] = 'w'; m_Letters[23] = 'x'; m_Letters[24] = 'y'; m_Letters[25] = 'z';
float startPosX = -460.0f;
float startPosY = -150.0f;
float stepX = 45.0f;
float stepY = 45.0f;
int columnCount = 6;
int rowCount = 4;
int id = 0;
int currentColumn = 0;
int currentRow = 0;
m_pMenu = CCMenu::create();
for(int i=0;i<m_Letters.size();i++)
{
Point pos = Point(startPosX+(currentColumn*stepX),startPosY+(-currentRow*stepY));
CCMenuItem * button = CCMenuItemImage::create(
"base.png",
"fixed.png",
this,
menu_selector(CChooseLetterWindow::LetterBtnClick));
button->setTag(int(m_Letters[i]));
button->setScale(0.35f);
button->setPosition(pos);
LabelTTF * letterLabel = LabelTTF::create("0","helvetica",82);
letterLabel->setPosition(button->getContentSize().width/2,button->getContentSize().height/2);
letterLabel->setColor(Color3B(0,0,0));
std::string str = "A";
str[0] = m_Letters[i];
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
letterLabel->setString(str);
button->addChild(letterLabel);
//letterLabel->setPosition(pos);
currentColumn++;
if(currentColumn == columnCount)
{
currentColumn = 0;
currentRow++;
}
m_pMenu->addChild(button);
m_pMenu->setEnabled(false);
}
m_Back->addChild(m_pMenu);
return true;
}
示例3: initPassAndPlay
bool MainMenu::initPassAndPlay()
{
this->removeChildByTag( Child::CCMenuItem_passAndPlay, true );
CCMenuItem* item = CCMenuItem::create( this, menu_selector( MainMenu::passAndPlayCallback ) );
CCSprite* sprite = CCSprite::create( "button_passAndPlay.png" );
sprite->setAnchorPoint(CCPointZero);
item->setContentSize( sprite->getContentSize() );
item->addChild( sprite );
CCLabelTTF* label = CCLabelTTF::create("Pass and Play", "American Typewritter.ttf", 24);
label->setAnchorPoint(CCPointZero);
label->setPosition( ccp( sprite->getContentSize().width * 0.25, sprite->getContentSize().height * 0.5 ) );
item->addChild(label);
this->addChild( item, 0, Child::CCMenuItem_passAndPlay );
return true;
}
示例4: tabViewInitPage
bool ActorBoardLayer::tabViewInitPage( CCNode* pTabLayer,cocos2d::CCNode *pPage, int nPage)
{
char str[64] = {0};
sprintf(str, "%d", nPage);
CCMenuItem* menuitem = CCMenuItem::create();
CCLabelTTF* text = CCLabelTTF::create(
str, "Arial", 22);
text->setAnchorPoint(CCPointZero);
text->setColor(ccBLACK);
menuitem->addChild(text);
pPage->addChild(menuitem);
return true;
}
示例5: fillBanner
void ADAds::fillBanner(Banner* banner)
{
#if defined(_DEBUG) && CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
CCRenderTexture* texture = CCRenderTexture::create(100, 100);
texture->beginWithClear(0.5f, 0.5f, 0.5f, 1);
texture->end();
CCSprite* s = CCSprite::createWithTexture(texture->getSprite()->getTexture());
s->setScaleX(banner->getContentSize().width/s->getContentSize().width);
s->setScaleY(banner->getContentSize().height/s->getContentSize().width);
banner->addChild(s);
s->setAnchorPoint(ccp(0,0));
s->setPosition(ccp(0,0));
#endif
if(_home_banners.size())
{
//std::random_shuffle(_home_banners.begin(), _home_banners.end());
CustomBanner* home_ads = getCustomBanner();
CCMenuItem* item = CCMenuItem::create(
home_ads, menu_selector(CustomBanner::onClick));
CCMenu* menu = CCMenu::create();
menu->addChild(item);
banner->addChild(menu, 0, HOME_ADS_NODE_TAG);
menu->setAnchorPoint(ccp(0,0));
menu->setPosition(ccp(0,0));
CCNode* banner_content = home_ads->getBanner();
CCSize content_size = banner_content->getContentSize();
CCSize zone_size = banner->getContentSize();
float scale = MIN(zone_size.width/content_size.width,
zone_size.height/content_size.height);
banner_content->setScale(scale);
banner_content->setAnchorPoint(ccp(0, 0));
banner_content->setPosition(ccp(0,0));
item->setContentSize(content_size*scale);
item->setAnchorPoint(ccp(0.5f,0.5f));
item->setPosition(zone_size*0.5f);
item->addChild(banner_content);
}
}
示例6:
CCMenuItem *EPSpriteButton::itemWithSpriteFrame(CCSpriteFrame *spriteFrame1,
CCSpriteFrame *spriteFrame2,
CCSpriteFrame *contentSpriteFrame)
{
CCSprite *sp1 = CCSprite::spriteWithSpriteFrame(spriteFrame1);
CCSprite *sp2 = CCSprite::spriteWithSpriteFrame(spriteFrame2);
CCSprite *content = CCSprite::spriteWithSpriteFrame(contentSpriteFrame);
CCMenuItem *item = CCMenuItemSprite::itemFromNormalSprite(sp1,sp2);
content->setPosition(ccp(item->getContentSize().width/2,item->getContentSize().height/2));
item->addChild(content);
return item;
}
示例7: addLabel
void DropDownListSprite:: addLabel(CCLabelTTF * label)
{
CCSize size = getContentSize();
CCLayerColor * normal = CCLayerColor::create(DROPDOWNLIST_NORMAL_COLOR,size.width,size.height);
CCLayerColor * selected = CCLayerColor::create(DROPDOWNLIST_SELECTED_COLOR, size.width, size.height);
m_bgLayers.push_back(normal);
m_selectLabels.push_back(label);
CCMenuItem * item = CCMenuItemSprite::create(normal, selected, NULL,this, SEL_MenuHandler(&DropDownListSprite::onSelected));
label->setPosition(ccp(size.width/2, size.height/2));
item->addChild(label);
item->setTag((int)m_selectLabels.size()-1);
item->setPosition(ccp(0,- (int)m_selectLabels.size() * size.height));
m_mainMenu->addChild(item);
}
示例8: BuildBikes
void Store::BuildBikes(cocos2d::CCMenu* menu)
{
float scale = ScreenHelper::getTextureScale();
CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped));
topBar->setScale(scale);
CCLabelTTF* label1 = CCLabelTTF::create("BIKES","Jacoby ICG Black.ttf",20);
label1->setColor(ccc3(43,197,231));
label1->setPosition(ccp(-170+CATEGORY_OFFSET,17));
topBar->addChild(label1);
menu->addChild(topBar);
for(int i = 0; i < NUM_BIKE_ITEMS; i++)
{
CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::bikeButtonTapped) );
CCSprite *sprite = CCSprite::createWithSpriteFrameName(s_BikeItemImg[i]);
sprite->setPosition(ccp(ICON_X,ICON_Y));
temp->addChild(sprite);
CCSize dim;
dim.width = 200.0f;
dim.height = 25.0f;
CCLabelTTF *label = CCLabelTTF::create(s_BikeItemName[i],"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(237,188,0));
label->setPosition(ccp(NAME_X,NAME_Y));
temp->addChild(label);
const char *status = NULL;
if(SaveLoad::m_SaveData.bikes[i] & SaveLoad::SELECTED)
status = "Selected";
else if(SaveLoad::m_SaveData.bikes[i] & SaveLoad::UNLOCKED)
status = "Unlocked";
else
status = "Locked";
dim.width = 400.0f;
dim.height = 18.0f;
label = CCLabelTTF::create(status,"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(230,230,230));
label->setPosition(ccp(DESC_X,DESC_Y));
temp->addChild(label,0,15);
m_BikeDescriptions[i] = label;
if(SaveLoad::m_SaveData.bikes[i]==0)
{
//CGSize dim;
dim.width = 50.0f;
dim.height = 20.0f;
char currencyStr[32];
sprintf(currencyStr,"$%d",s_BikeItemCost[i]);
CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt");
BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f));
BMfontLabel->setPosition(ccp(COST_X,COST_Y));
temp->addChild(BMfontLabel,0,42);
}
temp->setScale(scale);
menu->addChild(temp);
m_Bikebuttons[i] = temp;
}
//add a bottom bar to push things up
topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped));
topBar->setScale(scale);
menu->addChild(topBar);
}
示例9: BuildPowerUps
void Store::BuildPowerUps(cocos2d::CCMenu* menu)
{
float scale = ScreenHelper::getTextureScale();
CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped));
topBar->setScale(scale);
CCLabelTTF* label1 = CCLabelTTF::create("POWERUPS","Jacoby ICG Black.ttf",20);
label1->setColor(ccc3(43,197,231));
label1->setPosition(ccp(-148+CATEGORY_OFFSET,17));
topBar->addChild(label1);
menu->addChild(topBar);
for(int i = 0; i < NUM_POWERUP_ITEMS; i++)
{
CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::powerupButtonTapped) );
CCSprite *sprite = CCSprite::createWithSpriteFrameName(s_PowerUpItemImg[i]);
sprite->setPosition(ccp(ICON_X,ICON_Y));
temp->addChild(sprite);
char labelString[32];
if(i==0)
{
if(SaveLoad::m_SaveData.numLevelFire)
sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numLevelFire);
else
sprintf(labelString,"%s",s_PowerUpItemName[i]);
}
if(i==1)
{
if(SaveLoad::m_SaveData.numTimeSlow)
sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numTimeSlow);
else
sprintf(labelString,"%s",s_PowerUpItemName[i]);
}
if(i==2)
{
if(SaveLoad::m_SaveData.numDoubleNuts)
sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numDoubleNuts);
else
sprintf(labelString,"%s",s_PowerUpItemName[i]);
}
CCSize dim;
dim.width = 200.0f;
dim.height = 25.0f;
CCLabelTTF *label = CCLabelTTF::create(labelString,"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(237,188,0));
label->setPosition(ccp(NAME_X,NAME_Y));
temp->addChild(label);
m_PowerUpNames[i] = label;
dim.width = 400.0f;
dim.height = 18.0f;
label = CCLabelTTF::create(s_PowerUpItemDesc[i],"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(230,230,230));
label->setPosition(ccp(DESC_X,DESC_Y));
temp->addChild(label,0,15);
//CGSize dim;
dim.width = 50.0f;
dim.height = 20.0f;
char currencyStr[32];
sprintf(currencyStr,"$%d",s_PowerUpItemCost[i]);
CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt");
BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f));
BMfontLabel->setPosition(ccp(COST_X,COST_Y));
temp->addChild(BMfontLabel);
temp->setScale(scale);
menu->addChild(temp);
m_PowerUpbuttons[i] = temp;
}
}
示例10: BuildUpgrades
void Store::BuildUpgrades(cocos2d::CCMenu* menu)
{
float scale = ScreenHelper::getTextureScale();
CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped));
topBar->setScale(scale);
CCLabelTTF* label1 = CCLabelTTF::create("UPGRADES","Jacoby ICG Black.ttf",20);
label1->setColor(ccc3(43,197,231));
label1->setPosition(ccp(-150+CATEGORY_OFFSET,17));
topBar->addChild(label1);
menu->addChild(topBar);
int unlockLevel[NUM_UPGRADE_ITEMS];
unlockLevel[0] = SaveLoad::m_SaveData.turboLockLevel;
unlockLevel[1] = SaveLoad::m_SaveData.trampLockLevel;
unlockLevel[2] = SaveLoad::m_SaveData.timeLockLevel;
unlockLevel[3] = SaveLoad::m_SaveData.peanutLockLevel;
unlockLevel[4] = SaveLoad::m_SaveData.trickLockLevel;
unlockLevel[5] = SaveLoad::m_SaveData.flipLockLevel;
unlockLevel[6] = SaveLoad::m_SaveData.fireLockLevel;
for(int i = 0; i < NUM_UPGRADE_ITEMS; i++)
{
CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::buyUpgradeButtonTapped) );
CCSprite *sprite;
sprite = CCSprite::create("ctm_Store_PurchaseBars.png");
sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+302-120,POWER_UP_BAR_OFFSET_Y+21));
temp->addChild(sprite);
if(unlockLevel[i]>=1)
{
sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png");
sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+290-120,POWER_UP_BAR_OFFSET_Y+20));
temp->addChild(sprite);
}
if(unlockLevel[i]>=2)
{
sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png");
sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+305-120,POWER_UP_BAR_OFFSET_Y+20));
temp->addChild(sprite);
}
if(unlockLevel[i]>=3)
{
sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png");
sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+320-120,POWER_UP_BAR_OFFSET_Y+20));
temp->addChild(sprite);
}
sprite = CCSprite::createWithSpriteFrameName(s_UpgradeItemImg[i]);
sprite->setPosition(ccp(ICON_X,ICON_Y));
temp->addChild(sprite);
CCSize dim;
dim.width = 200.0f;
dim.height = 25.0f;
CCLabelTTF *label = CCLabelTTF::create(s_UpgradeItemName[i],"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(237,188,0));
label->setPosition(ccp(NAME_X,NAME_Y));
temp->addChild(label);
dim.width = 400.0f;
dim.height = 18.0f;
label = CCLabelTTF::create(s_UpgradeItemDesc[i][unlockLevel[i]],"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft);
label->setColor(ccc3(230,230,230));
label->setPosition(ccp(DESC_X,DESC_Y));
temp->addChild(label,0,15);
//CGSize dim;
dim.width = 50.0f;
dim.height = 20.0f;
char currencyStr[32];
if(s_UpgradeItemCost[i][unlockLevel[i]] > 0)
sprintf(currencyStr,"$%d",s_UpgradeItemCost[i][unlockLevel[i]]);
else
sprintf(currencyStr,"Max");
CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt");
BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f));
BMfontLabel->setPosition(ccp(COST_X,COST_Y));
m_UpgradeCosts[i] = BMfontLabel;
temp->addChild(BMfontLabel);
temp->setScale(scale);
menu->addChild(temp);
m_UpgradeButtons[i] = temp;
}
}
示例11: init
bool CSLayerPopupMsg::init(POPUPMSG_ENUM popEnum, string strTitle, string strMessage)
{
m_strMessage = strMessage;
m_strTitle = strTitle;
m_popEnum = popEnum;
CCSize size = CCDirector::sharedDirector()->getWinSize();
//添加背景
CCSprite *pSprite = CCSprite::spriteWithSpriteFrameName(m_strBackground.c_str());
pSprite->setPosition(ccp(size.width/2, size.height/2));
addChild(pSprite);
//标题栏
CCLabelTTF *pLabel = CCLabelTTF::labelWithString(m_strTitle.c_str(), "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(size.width*2/5, size.height*7/10));
pLabel->setColor(ccc3(200,200,255));
pSprite->addChild(pLabel);
//信息
pLabel = CCLabelTTF::labelWithString(m_strMessage.c_str(), "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(size.width/2, size.height/2));
pLabel->setColor(ccc3(155,155,255));
pSprite->addChild(pLabel);
//添加按钮
CCMenu *pMenu = CCMenu::menuWithItems(NULL);
pMenu->setPosition(CCPointZero);
CCMenuItem *pItem;
if (m_popEnum == POPUP_YESNOCANCEL)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_NO);
pItem->setPosition(ccp(size.width*5/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_CANCEL);
pItem->setPosition(ccp(size.width*7/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("关闭", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
else if (m_popEnum == POPUP_YESNO)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_NO);
pItem->setPosition(ccp(size.width*5/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
else if (m_popEnum == POPUP_YES)
{
pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick));
pItem->setTag(RESPONSE_YES);
pItem->setPosition(ccp(size.width*3/10, size.height*2/5));
pMenu->addChild(pItem, 0);
pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28);
pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2));
pItem->addChild(pLabel);
}
addChild(pMenu);
return true;
}
示例12: BuildMenu
void GetPeanuts::BuildMenu()
{
float scale = ScreenHelper::getTextureScale();
float scaleX = ScreenHelper::getTextureScaleX();
float scaleY = ScreenHelper::getTextureScaleY();
CCMenu *screenMenu = CCMenu::create();
CCSize dim;
dim.width = 200.0f;
dim.height = 35.0f;
for(int i = 0; i < 4; i++)
{
CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png","ctm_Store_LitStrip.png",this,menu_selector(GetPeanuts::buyButtonTapped) );
CCSprite *sprite = NULL;
switch(i)
{
case 0:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_A.png");
break;
case 1:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_B.png");
break;
case 2:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_C.png");
break;
case 3:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_D.png");
break;
}
sprite->setPosition(ccp(312/2-16,33));
temp->addChild(sprite);
const char *amount;
const char *cost;
switch(i)
{
case 0:
amount = "3,000";
cost = "$1.99";
break;
case 1:
amount = "35,000";
cost = "$7.99";
break;
case 2:
amount = "100,000";
cost = "$14.99";
break;
case 3:
amount = "300,000";
cost = "$24.99";
break;
}
CCLabelTTF *label = CCLabelTTF::create(amount,"Jacoby ICG Black.ttf",30,dim,kCCTextAlignmentRight);
label->setColor(ccc3(237,188,0));
label->setPosition(ccp(200,46));
temp->addChild(label);
CCSize dim;
dim.width = 70.0f;
dim.height = 20.0f;
label = CCLabelTTF::create(cost,"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentRight);
label->setColor(ccc3(230,230,230));
label->setPosition(ccp(260,23));
temp->addChild(label);
temp->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,-250.0f,-i*50));
temp->setScale(scale);
screenMenu->addChild(temp);
m_MenuItems[i] = temp;
}
screenMenu->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,86,-119));
addChild(screenMenu);
}