本文整理汇总了C++中CCMenuItem::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItem::setPosition方法的具体用法?C++ CCMenuItem::setPosition怎么用?C++ CCMenuItem::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItem
的用法示例。
在下文中一共展示了CCMenuItem::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitDialog
bool HSGoldInadequateDialog::InitDialog()
{
CCSprite* pBackground = CCSprite::create("Image/SelectChannel/goumaijinbidikuang.png");
pBackground->setPosition(ccp(307,480));
this->addChild(pBackground);
CCSprite* pGoldFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png");
pGoldFrame->setPosition(ccp(236,202));
pBackground->addChild(pGoldFrame);
CCSprite* pMoneyFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png");
pMoneyFrame->setPosition(ccp(520,202));
pBackground->addChild(pMoneyFrame);
const message::PropInfoData* pPropInfodata = HS_GAME_CACHE()->GetPropInfoData();
for (int i =0;i<pPropInfodata->buygoldlist_size();++i)
{
int temp = pPropInfodata->buygoldlist(i).gold_number();
if ((int)m_buyGold.gold_number() < temp)
{
m_buyGold = pPropInfodata->buygoldlist(i);
}
if (temp > HS_GAME_CACHE()->GetGold())
{
m_buyGold = pPropInfodata->buygoldlist(i);
break;
}
}
CCLabelTTF* pGoldTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.gold_number())->getCString(),HS_FONT_HuaKang,36.f);
pGoldTTF->setAnchorPoint(HS_ANCHOR_L_CENTER);
pGoldTTF->setPosition(ccp(0,pGoldTTF->getContentSize().height - pGoldTTF->getFontSize() / 2.f));
pGoldFrame->addChild(pGoldTTF);
CCLabelTTF* pMoneyTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.money())->getCString(),HS_FONT_HuaKang,36.f);
pMoneyTTF->setAnchorPoint(HS_ANCHOR_L_CENTER);
pMoneyTTF->setPosition(ccp(0,pMoneyTTF->getContentSize().height - pMoneyTTF->getFontSize() / 2.f));
pMoneyFrame->addChild(pMoneyTTF);
CCMenuItem* pGoRoomItem = CCMenuItemImage::create("Image/SelectChannel/dibeilvchang_01.png","Image/SelectChannel/dibeilvchang_02.png",this,menu_selector(HSGoldInadequateDialog::Call_GoRoom));
pGoRoomItem->setPosition(ccp(169,322));
this->PushMenu(pGoRoomItem);
CCMenuItem* pBuyItem = CCMenuItemImage::create("Image/SelectChannel/goumai_01.png","Image/SelectChannel/goumai_02.png",this,menu_selector(HSGoldInadequateDialog::Call_Buy));
pBuyItem->setPosition(ccp(456,322));
this->PushMenu(pBuyItem);
return true;
}
示例2: createUI
void IntroScene::createUI()
{
// Add background image
CCSprite* bg_spt = CCSprite::create(getResPath(INTRO_BACKGROUND_IMGAE));
bg_spt->setScaleX(SCALEX);
bg_spt->setScaleY(SCALEY);
bg_spt->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5));
this->addChild(bg_spt);
// Add description bg
CCSprite* des_bg = CCSprite::create(getResPath(INTRO_DESCRIPTION_BG_IMG));
des_bg->setScaleX(SCALEX);
des_bg->setScaleY(SCALEY * 0.5);
des_bg->setPosition(ccp(winSize.width * 0.5, 798 * SCALEY));
this->addChild(des_bg);
// Add description text
CCSprite* des = CCSprite::create(getResPath(INTRO_DESCRIPTION_IMG));
des->setScale(MIN(SCALEX, SCALEY));
des->setPosition(ccp(winSize.width * 0.5, 800 * SCALEY));
this->addChild(des);
// Add character
CCSprite* character = CCSprite::create(getResPath(INTRO_CHARACTER_IMG));
character->setScale(SCALE * 0.9);
character->setPosition(ccp(167 * SCALEX, 385 * SCALEY));
this->addChild(character);
// Add blue and yellow chair
CCSprite* bl_chair = CCSprite::create(getResPath(CHAIR_BLUE_IMG));
bl_chair->setScale(SCALE * 0.9);
bl_chair->setPosition(ccp(140 * SCALEX, 243 * SCALEY));
this->addChild(bl_chair);
CCSprite* yl_chair = CCSprite::create(getResPath(CHAIR_YELLOW_IMG));
yl_chair->setScale(SCALE * 0.9);
yl_chair->setPosition(ccp(506 * SCALEX, 243 * SCALEY));
this->addChild(yl_chair);
// Add play, mainmenu buttons
CCMenuItem* playItem = CCMenuItemImage::create(getResPath(INTRO_PLAY_BUTTON_IMAGE_NOR), getResPath(INTRO_PLAY_BUTTON_IMAGE_PRS), this, menu_selector(IntroScene::gotoplay));
playItem->setScale(MIN(SCALEX, SCALEY));
playItem->setPosition(175 * SCALEX, 50 * SCALEY);
CCMenuItem* mainmenuItem = CCMenuItemImage::create(getResPath(INTRO_MAINMENU_BUTTON_IMAGE_NOR), getResPath(INTRO_MAINMENU_BUTTON_IMAGE_PRS), this, menu_selector(IntroScene::gotoMainMenu));
mainmenuItem->setScale(MIN(SCALEX, SCALEY));
mainmenuItem->setPosition(467 * SCALEX, 50 * SCALEY);
CCMenu* menu = CCMenu::create(playItem, mainmenuItem, NULL);
menu->setPosition(CCPointZero);
this->addChild(menu);
}
示例3: Init_Button
void GameUI_MainTitle_Store::Init_Button()
{
CCMenuItem* eraser = CCMenuItemImage::create("b_buy.png", "b_buy.png",
this,menu_selector(GameUI_MainTitle_Store::ButtonDelegate_Eraser));
CCMenuItem* undo = CCMenuItemImage::create("b_buy.png", "b_buy.png",
this,menu_selector(GameUI_MainTitle_Store::ButtonDelegate_Undo));
eraser->setPosition(ccp(533, 1280-413));
undo->setPosition(ccp(533, 1280-652));
CCMenu* menu = CCMenu::create(eraser, undo, NULL);
menu->setPosition(ccp(0,0));
this->addChild(menu);
}
示例4: addMenu
void MapMenu::addMenu()
{
if (spriteBackButton != NULL) {
spriteBackButton->removeFromParentAndCleanup(false);
}
spriteBackButton = CCSprite::create("Background_Estacionamento_botoes.png");
spriteBackButton->setAnchorPoint(ccp(0, 0));
CCSize winsize = CCDirector::sharedDirector()->getWinSize();
if (winsize.height > 480) {
spriteBackButton->setPosition(ccp(0, 430));
}
else
{
spriteBackButton->setPosition(ccp(0, 350));
}
layer->addChild(spriteBackButton, 100) ;
CCMenuItem *pOpenMapItem;
CCMenuItem *pOpen3DItem;
if(type == MAP_NORMAL )
{
pOpenMapItem = CCMenuItemImage::create("button_comochegar_pressed.png","button_comochegar_pressed.png",this,menu_selector(MapMenu::openMap));
pOpen3DItem = CCMenuItemImage::create("button_3d_on.png","button_3d_on.png",this,menu_selector(MapMenu::open3D));
}
else
{
pOpenMapItem = CCMenuItemImage::create("button_comochegar_on.png","button_comochegar_on.png",this,menu_selector(MapMenu::openMap));
pOpen3DItem = CCMenuItemImage::create("button_3d_pressed.png","button_3d_pressed.png",this,menu_selector(MapMenu::open3D));
}
pOpenMapItem->setAnchorPoint(ccp(0, 0));
pOpenMapItem->setPosition(ccp(0, 0));
pOpen3DItem->setAnchorPoint(ccp(0, 0));
pOpen3DItem->setPosition(ccp(110, 00));
// pCloseItem->setFontSize(35);
// pCloseItem->setFontName("Helvetica");
if (menu != NULL) {
menu->removeFromParentAndCleanup(false);
}
menu = CCMenu::create(pOpenMapItem,pOpen3DItem,NULL);
menu->setAnchorPoint(ccp(0, 0));
if (winsize.height > 480) {
menu->setPosition(ccp(50, 450));
}
else
{
menu->setPosition(ccp(50, 360));
}
layer->addChild(menu,101);
}
示例5: 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;
}
示例6: InitDialog
bool HSGoldInadequateDialog::InitDialog()
{
CCSprite* pBackground = HSCCSprite::create("Image/goumaijinbidikuang.png");
pBackground->setPosition(ccp(307,480));
this->addChild(pBackground);
CCSprite* pGoldFrame = HSCCSprite::create("Image/Mingziditu.png");
pGoldFrame->setPosition(ccp(236,202));
pBackground->addChild(pGoldFrame);
CCSprite* pMoneyFrame = HSCCSprite::create("Image/Mingziditu.png");
pMoneyFrame->setPosition(ccp(520,202));
pBackground->addChild(pMoneyFrame);
m_pGoldTTF = CCLabelTTF::create(CCString::createWithFormat("%d",0/*m_buyGold->gold_number()*/)->getCString(),HS_FONT_HuaKang,36.f);
m_pGoldTTF->setAnchorPoint(HS_ANCHOR_L_CENTER);
m_pGoldTTF->setPosition(ccp(0,m_pGoldTTF->getContentSize().height - m_pGoldTTF->getFontSize() / 2.f));
pGoldFrame->addChild(m_pGoldTTF);
m_pMoneyTTF = CCLabelTTF::create(CCString::createWithFormat("%d",0/*m_buyGold->money()*/)->getCString(),HS_FONT_HuaKang,36.f);
m_pMoneyTTF->setAnchorPoint(HS_ANCHOR_L_CENTER);
m_pMoneyTTF->setPosition(ccp(0,m_pMoneyTTF->getContentSize().height - m_pMoneyTTF->getFontSize() / 2.f));
pMoneyFrame->addChild(m_pMoneyTTF);
CCNode* pItemNode_01 = HSCCSprite::create("Image/dibeilvchang_01.png");
CCNode* pItemNode_02 = HSCCSprite::create("Image/dibeilvchang_02.png");
CCMenuItem* pGoRoomItem = CCMenuItemSprite::create(pItemNode_01,pItemNode_02,this,menu_selector(HSGoldInadequateDialog::Call_GoRoom));
pGoRoomItem->setPosition(ccp(169,322));
this->PushMenu(pGoRoomItem);
CCNode* pItemNode_03 = HSCCSprite::create("Image/goumai_01.png");
CCNode* pItemNode_04 = HSCCSprite::create("Image/goumai_02.png");
CCMenuItem* pBuyItem = CCMenuItemSprite::create(pItemNode_03,pItemNode_04,this,menu_selector(HSGoldInadequateDialog::Call_Buy));
pBuyItem->setPosition(ccp(456,322));
this->PushMenu(pBuyItem);
return true;
}
示例7: setSelectedIndex
void CCMenuItemToggle::setSelectedIndex(unsigned int index)
{
if( index != m_uSelectedIndex )
{
m_uSelectedIndex = index;
this->removeChildByTag(kCurrentItem, false);
CCMenuItem *item = m_pSubItems->getObjectAtIndex(m_uSelectedIndex);
this->addChild(item, 0, kCurrentItem);
CGSize s = item->getContentSize();
this->setContentSize(s);
item->setPosition( ccp( s.width/2, s.height/2 ) );
}
}
示例8: 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);
}
}
示例9: 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);
}
示例10: setSelectedIndex
void CCMenuItemToggle::setSelectedIndex(unsigned int index)
{
if( index != m_uSelectedIndex && m_pSubItems->count() > 0 )
{
m_uSelectedIndex = index;
CCMenuItem *currentItem = (CCMenuItem*)getChildByTag(kCurrentItem);
if( currentItem )
{
currentItem->removeFromParentAndCleanup(false);
}
CCMenuItem* item = (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex);
this->addChild(item, 0, kCurrentItem);
CCSize s = item->getContentSize();
this->setContentSize(s);
item->setPosition( ccp( s.width/2, s.height/2 ) );
}
}
示例11: setTouchEnabled
GetPeanuts::GetPeanuts()
{
// enable touches
setTouchEnabled( true );
float scale = ScreenHelper::getTextureScale();
float scaleX = ScreenHelper::getTextureScaleX();
float scaleY = ScreenHelper::getTextureScaleY();
CCSprite *spriteReturn = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn.png");
CCSprite *spriteReturnDown = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn_Down.png");
CCMenuItem *returnButton = CCMenuItemSprite::create(spriteReturn,spriteReturnDown,this,menu_selector(GetPeanuts::returnButtonTapped));
returnButton->setScale(scale);
returnButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,90.0f,130.0f));
CCMenu* backmenu = CCMenu::create(returnButton, NULL);
backmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
addChild(backmenu,4);
setPosition(CCPointMake(-480*scaleX, 0));
runAction(CCMoveBy::create(0.15f,CCPointMake(480*scaleX, 0)));
bMenuBuilt = false;
isReturning = false;
if(SaveLoad::m_SaveData.beenToPeanuts==0)
{
SaveLoad::m_SaveData.beenToPeanuts=1;
SaveLoad::Save();
// [TestFlight passCheckpoint:@"PEANUT_VISIT"];
}
scheduleUpdate();
}
示例12: setTouchEnabled
Options::Options()
{
setTouchEnabled( true );
float scale = ScreenHelper::getTextureScale();
float scaleX = ScreenHelper::getTextureScaleX();
float scaleY = ScreenHelper::getTextureScaleY();
CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist");
CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist");
CCSprite *sprite = CCSprite::create("MainBackFiller.png");
sprite->setScaleX(scaleX*1.2f);
sprite->setScaleY(scaleY*1.2f);
sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f));
addChild(sprite);
sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png");
sprite->setScaleX(scaleX);
sprite->setScaleY(scaleY);
sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER));
addChild(sprite,2);
CCLabelTTF *label = CCLabelTTF::create("OPTIONS", "impact.ttf", 42*scale);
addChild(label, 2);
label->setColor(ccc3(0,0,0));
label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f));
label = CCLabelTTF::create("OPTIONS", "impact.ttf", 42*scale);
addChild(label, 2);
label->setColor(ccc3(237,188,0));
label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f));
CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(Options::backButtonTapped));
BackButton->setScale(scale);
BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f));
CCMenuItem *QuestionMarkButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Button_20.png"), CCSprite::createWithSpriteFrameName("ctm_Button_20_Down.png"), this, menu_selector(Options::questionButtonTapped));
QuestionMarkButton->setScale(scale);
QuestionMarkButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_CENTER,0.0f,65.0f));
CCMenuItem *MoreGamesButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("MoreGames.png"), CCSprite::createWithSpriteFrameName("MoreGames_dn.png"), this, menu_selector(Options::moreGamesButtonTapped));
MoreGamesButton->setScale(scale);
MoreGamesButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,55.0f,65.0f));
CCMenuItem *CreditsButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("Credits.png"), CCSprite::createWithSpriteFrameName("Credits_dn.png"), this, menu_selector(Options::creditsButtonTapped));
CreditsButton->setScale(scale);
CreditsButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_RIGHT,-55.0f,65.0f));
CCLabelTTF *optionsLabel = NULL;
if(SaveLoad::m_SaveData.sfxVolume <= 0.0f)
optionsLabel = CCLabelTTF::create("SFX: OFF", "impact.ttf", 40*scale);
else
optionsLabel = CCLabelTTF::create("SFX: ON", "impact.ttf", 40*scale);
CCMenuItemLabel *SoundFX = CCMenuItemLabel::create(optionsLabel, this, menu_selector(Options::sfxButtonTapped));
SoundFX->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0, 20));
if(SaveLoad::m_SaveData.musicVolume <= 0.0f)
optionsLabel = CCLabelTTF::create("Music: OFF", "impact.ttf", 40*scale);
else
optionsLabel = CCLabelTTF::create("Music: ON", "impact.ttf", 40*scale);
CCMenuItemLabel *Music = CCMenuItemLabel::create(optionsLabel, this, menu_selector(Options::musicButtonTapped));
Music->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0, -20));
CCMenu* menu = CCMenu::create(BackButton, QuestionMarkButton, MoreGamesButton, CreditsButton, SoundFX, Music, NULL);
menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
addChild(menu,4);
scheduleUpdate();
}
示例13: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
this->isTouchEnabled();
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
/////////////////////////////
// 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(
// "CloseNormal.png",
// "CloseSelected.png",
// this,
// menu_selector(HelloWorld::menuCloseCallback));
//pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
//origin.y + pCloseItem->getContentSize().height/2));
CCMenuItem *pStartGameItem = CCMenuItemFont::create(
"Start Game",
this,
menu_selector(HelloWorld::startGame) );
pStartGameItem->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2));
CCMenuItem *pGameOptions = CCMenuItemFont::create(
"Options",
this,
menu_selector(HelloWorld::startOptionsMenu) );
pGameOptions->setPosition(ccp(origin.x + visibleSize.width - pGameOptions->getContentSize().width/2 ,
origin.y + pGameOptions->getContentSize().height/2));
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pStartGameItem, NULL);
pMenu->setPosition(CCPointZero);
pMenu->addChild(pGameOptions);
this->addChild(pMenu, 1);
/////////////////////////////
// 3. add your codes below...
// add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
CCLabelTTF* pLabel = CCLabelTTF::create("Ugly Brick Breaker EXTREME V0.1", "Arial", TITLE_FONT_SIZE);
// position the label on the center of the screen
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));
// add the label as a child to this layer
this->addChild(pLabel, 1);
CCLabelTTF* authorLabel = CCLabelTTF::create("By: Steven Bauer", "Arial", TITLE_FONT_SIZE);
authorLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - 30 - authorLabel->getContentSize().height));
this->addChild(authorLabel, 2);
return true;
}
示例14: createRLayer
CCLayer* RemindLayer::createRLayer(const char *tStr, int remindType){
CCLayer* layer = new CCLayer();
int tagOpen = 0;
int tagClose = 0;
bool typeOn;
switch (remindType) {
case EN_REMIND_ACTIVITY:
tagOpen = kActivityOnTag;
tagClose = kActivityOffTag;
typeOn = CGameData::Inst()->isActivityRemind;
break;
case EN_REMIND_TWOUP:
tagOpen = kTwoupOnTag;
tagClose = kTwoupOffTag;
typeOn = CGameData::Inst()->isTwoUpRemind;
break;
case EN_REMIND_CNTRYCD:
tagOpen = kCntryCdOnTag;
tagClose = kCntryCdOffTag;
typeOn = CGameData::Inst()->isCntryCdRemind;
break;
case EN_REMIND_POWER:{
tagOpen = kPowerOnTag;
tagClose = kPowerOffTag;
typeOn = CGameData::Inst()->intPowerRemind;
CCSprite* spMenu1 = CCSprite::spriteWithFile("pushConfig_tilizhi.png");
CCSprite* spMenu2 = CCSprite::spriteWithFile("pushConfig_tilizhi.png");
CCMenuItem* item = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2,
this, menu_selector(RemindLayer::MoveUpKeyboard));
item->setPosition(ccp(0,0));
item->setAnchorPoint(CCPointZero);
CCMenu *menu = CCMenu::menuWithItems (item, NULL);
menu->setPosition(ccp(-50,20));
layer->addChild(menu, 2);
char buf[100];
snprintf(buf, 99,"%d", CGameData::Inst()->intPowerRemind);
powerNumber = CCTextFieldTTF::textFieldWithPlaceHolder(buf,CCSizeMake(100, 200) ,CCTextAlignmentCenter,"huakangfont.ttf", 32);
powerNumber->setPosition(ccp(12, 40));
powerNumber->setColor(ccWHITE);
powerNumber->setDelegate(this);
layer->addChild(powerNumber,10);
CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
pGlView->setIMEKeyboardNumber();
break;
}
default:
tagOpen = kActivityOnTag;
tagClose = kActivityOffTag;
typeOn = CGameData::Inst()->isCntryCdRemind;
break;
}
CCSprite* spFrame = CCSprite::spriteWithFile("pushConfig_Bg.png");
spFrame->setPosition(CCPointMake(2, 0));
layer->addChild(spFrame);
TextNode *remindLabel = TextNode::textWithString(tStr, 32);
remindLabel->setColor(ccc3(255, 255, 255));
remindLabel->setShadowColor(ccc3(0, 0, 0));
remindLabel->setPosition(ccp(0,40));
layer->addChild(remindLabel);
CCSprite* spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_open.png");
CCSprite* spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_open.png");
CCSprite* spMenu3 = CCSprite::spriteWithSpriteFrameName("fr_open2.png");
CCMenuItem* item1 = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2,spMenu3,
this, menu_selector(RemindLayer::switchOnOff));
item1->setPosition(ccp(-170, -50));
item1->setAnchorPoint(ccp(0, 0));
item1->setTag(tagOpen);
spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_close.png");
spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_close.png");
spMenu3 = CCSprite::spriteWithSpriteFrameName("fr_close2.png");
CCMenuItem* item2 = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2,spMenu3,
this, menu_selector(RemindLayer::switchOnOff));
item2->setPosition(ccp(30, -50));
item2->setAnchorPoint(ccp(0, 0));
item2->setTag(tagClose);
item1->setIsEnabled(!typeOn);
item2->setIsEnabled(typeOn);
CCMenu *menu = CCMenu::menuWithItems (item1,item2,
NULL);
menu->setPosition(ccp(0, 0));
layer->addChild(menu);
return layer;
}
示例15: 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;
}