本文整理汇总了C++中CCMenu::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenu::setPosition方法的具体用法?C++ CCMenu::setPosition怎么用?C++ CCMenu::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenu
的用法示例。
在下文中一共展示了CCMenu::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool MainMenuCtrlLayer::init()
{
bool ret = false;
do {
CC_BREAK_IF(!CCLayer::init());
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// 菜单
// 菜单纹理
CCImage menuImage;
menuImage.initWithImageFile("menu.png");
CCTexture2D *menuTexture = new CCTexture2D();
menuTexture->initWithImage(&menuImage);
// 菜单选项
CCMenuItemSprite *newGameMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
newGameMenuItem->setTag(MAINMENU_ID_NEW_GAME);
CCMenuItemSprite *settingMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
settingMenuItem->setTag(MAINMENU_ID_SETTING);
CCMenuItemSprite *aboutMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
aboutMenuItem->setTag(MAINMENU_ID_ABOUT);
CCMenu *mainMenu = CCMenu::menuWithItems(newGameMenuItem, settingMenuItem, aboutMenuItem, NULL);
mainMenu->alignItemsVerticallyWithPadding(10);
mainMenu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 80));
this->addChild(mainMenu);
ret = true;
} while (0);
return ret;
}
示例2: showRateView
void GameScene::showRateView()
{
if (m_pRateLayer == NULL)
{
m_pRateLayer = LGLayerColor::create(ccc4(0, 0, 0, 0));
m_pRateLayer->retain();
m_pRateLayer->setTouchMode(kCCTouchesOneByOne);
m_pRateLayer->setTouchEnabled(true);
m_pRateLayer->setZOrder(3);
CCSprite *pBg = CCSprite::create("rate_bg.png");
pBg->setPosition(m_VisibleOrigin + m_VisibleSize / 2);
m_pRateLayer->addChild(pBg);
float bgW = pBg->getContentSize().width, bgH = pBg->getContentSize().height;
CCMenuItemImage *pRate = LGMenuItemImage::create("rate_rate.png", NULL, this, menu_selector(GameScene::rateCallback));
pRate->setPosition(ccp(pBg->getPositionX() - 0.2592593f * bgW, pBg->getPositionY() - 0.6566f * bgH));
CCMenuItemImage *pLater = LGMenuItemImage::create("rate_later.png", NULL, this, menu_selector(GameScene::laterCallback));
pLater->setPosition(ccp(pBg->getPositionX() + 0.2592593f * bgW, pRate->getPositionY()));
CCMenu *pMenu = CCMenu::create(pRate, pLater, NULL);
pMenu->setAnchorPoint(CCPointZero);
pMenu->setPosition(CCPointZero);
m_pRateLayer->addChild(pMenu);
}
if (m_pRateLayer && m_pRateLayer->getParent() == NULL)
{
getParent()->addChild(m_pRateLayer);
CC_SAFE_RELEASE_NULL(m_CurrentLayer);
m_CurrentLayer = m_pRateLayer;
m_CurrentLayer->retain();
onShowOverlay(true);
}
}
示例3: startGame
void HelloWorld::startGame()
{
// Initialize arrays
_targets = new CCArray();
_projectiles = new CCArray();
// Get the dimensions of the window for calculation purposes
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
player = (Player*)CCSprite::create("Player.png");
player->setPosition(ccp(player->getContentSize().width/2, winSize.height/2));
player->isEnemy = false;
addChild(player);
enemy = (Player*)CCSprite::create("Enemy.png");
enemy->setPosition(ccp(winSize.width-enemy->getContentSize().width/2, winSize.height/2));
enemy->isEnemy = true;
enemy->setOpacity(100);
addChild(enemy);
isConnected = true;
if (isFirstLaunch)
{
scheduleUpdate();
}
CCLabelTTF *buttonTitle = CCLabelTTF::create("Disconnect", "Marker Felt", 30);
buttonTitle->setColor(ccBLACK);
CCMenuItemLabel *startGameButton = CCMenuItemLabel::create(buttonTitle, this,menu_selector(HelloWorld::disconnect));
startGameButton->setPosition(ccp(winSize.width/2,winSize.height/4));
//printf("\nshowStartGameLayer = (%f,%f)",winSize.width/2,winSize.height/2);
CCMenu *pMenu = CCMenu::create(startGameButton,NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
}
示例4: init
/*
* 初始化
*/
bool Demo::init() {
// super init
if (!CCLayer::init()) {
return false;
}
CCMenuItemImage *pSellItem = CCMenuItemImage::create( "des.png",
"des.png",
this,
menu_selector(Demo::
option));
pSellItem->setAnchorPoint(ccp(0, 0));
pSellItem->setPosition(ccp(0, 0));
CCMenu* menu = CCMenu::create(pSellItem, NULL);
menu->setAnchorPoint(ccp(0, 0));
menu->setPosition(ccp(0, 0));
addChild(menu);
CCSprite* sp = CCSprite::create("desfont.png");
sp->setAnchorPoint(ccp(0.5, 0));
sp->setPosition(ccp(320, 50));
addChild(sp);
CCActionInterval * scale = CCScaleTo::create(1, 1.1);
CCActionInterval * scale1 = CCScaleTo::create(1.5, 1);
CCFiniteTimeAction * seq= CCSequence::create(scale, scale1, NULL);
CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
sp->runAction(repeatForever);
/**/
LoginLayer* login = LoginLayer::create();
login->setVisible(false);
login->setTouchEnabled(false);
this->addChild(login, 1, 100);
return true;
}
示例5: ccp
bool Bug1159Layer::init()
{
if (BugsTestBaseLayer::init())
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLayerColor *background = CCLayerColor::layerWithColor(ccc4f(255, 0, 255, 255));
addChild(background);
CCLayerColor *sprite_a = CCLayerColor::layerWithColorWidthHeight(ccc4f(255, 0, 0, 255), 700, 700);
sprite_a->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_a->setIsRelativeAnchorPoint(true);
sprite_a->setPosition(ccp(0.0f, s.height/2));
addChild(sprite_a);
sprite_a->runAction(CCRepeatForever::actionWithAction((CCActionInterval*) CCSequence::actions(
CCMoveTo::actionWithDuration(1.0f, ccp(1024.0f, 384.0f)),
CCMoveTo::actionWithDuration(1.0f, ccp(0.0f, 384.0f)),
NULL)));
CCLayerColor *sprite_b = CCLayerColor::layerWithColorWidthHeight(ccc4f(0, 0, 255, 255), 400, 400);
sprite_b->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_b->setIsRelativeAnchorPoint(true);
sprite_b->setPosition(ccp(s.width/2, s.height/2));
addChild(sprite_b);
CCMenuItemLabel *label = CCMenuItemLabel::itemWithLabel(CCLabelTTF::labelWithString("Flip Me", "Helvetica", 24), this, menu_selector(Bug1159Layer::callBack));
CCMenu *menu = CCMenu::menuWithItems(label, NULL);
menu->setPosition(ccp(s.width - 200.0f, 50.0f));
addChild(menu);
return true;
}
return false;
}
示例6: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCNode *pFishJoyScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FishJoy2.json");
this->addChild(pFishJoyScene);
cocos2d::extension::ActionManager::shareManager()->playActionByName("startMenu_1.json","Animation1");
CCMenuItemFont *itemBack = CCMenuItemFont::create("End", this, menu_selector(HelloWorld::menuCloseCallback));
itemBack->setColor(ccc3(255, 255, 255));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero);
menuBack->setZOrder(4);
this->addChild(menuBack);
return true;
}
示例7: 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();
}
示例8: onEnter
void EaseSpriteDemo::onEnter()
{
CCLayer::onEnter();
// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
m_grossini = CCSprite::spriteWithFile(s_pPathGrossini); m_grossini->retain();
m_tamara = CCSprite::spriteWithFile(s_pPathSister1); m_tamara->retain();
m_kathia = CCSprite::spriteWithFile(s_pPathSister2); m_kathia->retain();
addChild( m_grossini, 3);
addChild( m_kathia, 2);
addChild( m_tamara, 1);
CCSize s = CCDirector::sharedDirector()->getWinSize();
m_grossini->setPosition( CCPointMake(60, 50) );
m_kathia->setPosition( CCPointMake(60, 150) );
m_tamara->setPosition( CCPointMake(60, 250) );
CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
addChild(label);
label->setPosition( CCPointMake(s.width/2, s.height-50) );
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(EaseSpriteDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(EaseSpriteDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(EaseSpriteDemo::nextCallback) );
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
menu->setPosition( CCPointZero );
item1->setPosition( CCPointMake( s.width/2 - 100,30) );
item2->setPosition( CCPointMake( s.width/2, 30) );
item3->setPosition( CCPointMake( s.width/2 + 100,30) );
addChild(menu, 1);
}
示例9: onEnter
void CMemberListPopLayer::onEnter()
{
CPopLayerBase::onEnter();
Node *parent = getChildByTag( E_Tag_Bg );
if( !parent )
{
CCLog( "[CMemberListPopLayer::onEnter] get parent null" );
return;
}
CCMyMenuItemImage *closeItem = CCMyMenuItemImage::create(
"close_normal.png",
"close_hover.png",
this,
menu_selector(CMemberListPopLayer::menuCloseCallback) );
if( !closeItem )
{
CCLog( "[CMemberListPopLayer::onEnter] close item null" );
return;
}
Size szItem = closeItem->getContentSize();
Size szParent = parent->getContentSize();
closeItem->setAnchorPoint( ccp(0.5, 0.5) );
closeItem->setPosition( ccp( szParent.width-szItem.width, szParent.height-szItem.height ) );
CCMenu *menu = CCMenu::create( closeItem, NULL );
if( !menu )
{
CCLog( "[CMemberListPopLayer::onEnter] close menu null" );
return;
}
menu->setPosition( CCPointZero );
parent->addChild( menu, 1 );
_AddMemberList();
}
示例10: init
bool HelpLayer::init()
{
if (!CCLayer::init())
{
return false;
}
CCSize s = CCDirector::sharedDirector()->getWinSize();
//bg
CCSprite* bg = CCSprite::create(PIC_MAIN_BACKGROUND);
bg->setAnchorPoint(ccp(0,0));
addChild(bg);
//text
CCLabelTTF* text = CCLabelTTF::create(a2u(s_helpText).c_str(), "Arial", 40.0f, CCSizeMake(500,700), kCCTextAlignmentLeft);
text->setPosition(ccp(s.width*0.5, s.height*0.5));
addChild(text);
text = CCLabelTTF::create(a2u("北京天普教育").c_str(), "Arial", 30.0f);
text->setPosition(ccp(450, 250));
addChild(text);
//quit menu
CCMenuItemImage* quit = CCMenuItemImage::create(
PIC_BUTTON_BACK,
PIC_BUTTON_BACK_SELECTED,
this,
menu_selector(HelpLayer::quit));
CCMenu* menu = CCMenu::create(quit, NULL);
menu->setPosition(ccp(s.width*0.5, 120));
this->addChild(menu);
return true;
}
示例11: onEnter
void RS_Main::onEnter()
{
setKeypadEnabled(true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate((CCTargetedTouchDelegate *)this, 1, true);
CCLayerColor::onEnter();
char* szLang = LanguageUtil::getLanguageCode();
// 수학/과학 동화 미션 수행일 경우 안내 문구 출력
if(PROJECT_TYPE == TYPE_EDUNATION)
{
char szInfo[260];
sprintf(szInfo, "eBook/%02d/rememberStory/info_rs_%s.png", m_nCurEBookPage, szLang);
m_pInfoItem = CCMenuItemImage::create(szInfo, szInfo, this, menu_selector(RS_Main::menuClickCallback));
m_pInfoItem->setTag(4);
CCMenu* pInfo = CCMenu::create();
pInfo->addChild(m_pInfoItem);
pInfo->setPosition(ccp(s.width/2, s.height/2));
this->addChild(pInfo, 200);
// 미션으로 화면 전환시 이전화면과 구분을 위한 화면 전환 시간동안 표시할 하단 바 생성
m_pBottomBar = CCSprite::create("common/game/mission_bottom.png");
m_pBottomBar->setPosition(ccp(s.width/2, m_pBottomBar->getContentSize().height/2));
addChild(m_pBottomBar, 1000);
scheduleOnce(schedule_selector(RS_Main::invisibleBottomBar), 1.0f);
}
// Mission Played flag 설정
char cMissionPlayed[30];
sprintf(cMissionPlayed, "mission_played_%d_%s", m_nCurEBookPage, szLang);
CCUserDefault::sharedUserDefault()->setBoolForKey(cMissionPlayed, true);
CCUserDefault::sharedUserDefault()->flush();
}
示例12: init
bool UserInputScene::init()
{
if (!CCLayer::init())
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("welcome.plist","welcome.png");
CCSprite* bgSprite = CCSprite::create("login_2.png");
bgSprite->setAnchorPoint(CCPointZero);
bgSprite->setPosition(ccp(origin.x,origin.y));
this->addChild(bgSprite,9);
CCSprite* buttonSprite = CCSprite::create("start.png");
//buttonSprite->setAnchorPoint(CCPointZero);
//buttonSprite->setScale(0.5f);
//buttonSprite->setPosition(ccp(origin.x+visibleSize.width/2,origin.y));
//this->addChild(buttonSprite);
SEL_MenuHandler startSelect= (SEL_MenuHandler)menu_selector(UserInputScene::startGame);
CCMenuItemSprite* startMenu = CCMenuItemSprite::create(buttonSprite,
buttonSprite, buttonSprite, this,
startSelect );
CCMenu* menu = CCMenu::create(startMenu,NULL);
menu->setPosition(ccp(origin.x+visibleSize.width/2,origin.y));
menu->setScale(0.5f);
addChild(menu,10);
CCSize editBoxSize = CCSizeMake(visibleSize.width - 100, 60);
// top
m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png"));
m_pEditName->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height*3/4));
m_pEditName->setFontSize(25);
m_pEditName->setFontColor(ccRED);
m_pEditName->setPlaceHolder("Name:");
m_pEditName->setPlaceholderFontColor(ccWHITE);
m_pEditName->setMaxLength(8);
m_pEditName->setReturnType(kKeyboardReturnTypeDone);
m_pEditName->setDelegate(this);
addChild(m_pEditName,10);
m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png"));
m_pEditPassword->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
m_pEditPassword->setFontColor(ccGREEN);
m_pEditPassword->setPlaceHolder("Password:");
m_pEditPassword->setMaxLength(6);
m_pEditPassword->setInputFlag(kEditBoxInputFlagPassword);
m_pEditPassword->setInputMode(kEditBoxInputModeSingleLine);
m_pEditPassword->setDelegate(this);
addChild(m_pEditPassword,10);
//////////////////////////////////////////////////////////////////////////
//UILayer* ul = UILayer::create();
//UILayout* widget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("SelectSong1_1.json"));
//ul->addWidget(widget);
//Button* startBT = (Button*)ul->getWidgetByName("Button_28");
//startBT->addTouchEventListener(this,toucheventselector(UserInputScene::startGame));
//////////////////////////////////////////////////////////////////////////
return true;
}
示例13: init
// on "init" you need to initialize your instance
bool ControlLayer::init()
{
// 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
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png",
this,
menu_selector(ControlLayer::menuCloseCallback) );
pCloseItem->setPosition( ccp(winSize.width-20, 20) );
pCloseItem->setScale(0.5);
pCloseItem->setOpacity(200);
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
CCMenuItemImage *upItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveup));
CCMenuItemImage *downItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Movedown));
CCMenuItemImage *rightItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveright));
CCMenuItemImage *leftItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveleft));
int bX; //the x coordination
int bY; //the y coordination
int sizeAdjustionRatioConstant = 3; // for the auto adjusting size
float bScale = winSize.height / (sizeAdjustionRatioConstant * 100); // (screenHeight / buttonHeight) * ratioConstant
int transparence = 30;
bX = (winSize.width / 2);
bY = (winSize.height / 6) * 5;
upItem->setPosition( ccp(bX, bY) );
upItem->setOpacity(transparence);
upItem->setScale(bScale);
bX = (winSize.width / 2);
bY = (winSize.height / 6) * 1;
downItem->setPosition( ccp(bX, bY) );
downItem->setOpacity(transparence);
downItem->setRotation(180);
downItem->setScale(bScale);
bX = (winSize.width / 6) * 5;
bY = (winSize.height / 2);
rightItem->setPosition( ccp(bX, bY) );
rightItem->setOpacity(transparence);
rightItem->setRotation(90);
rightItem->setScale(bScale);
bX = (winSize.width / 6) * 1;
bY = (winSize.height / 2);
leftItem->setPosition( ccp(bX, bY) );
leftItem->setOpacity(transparence);
leftItem->setRotation(270);
leftItem->setScale(bScale);
CCMenu* moveItem = CCMenu::create(upItem, downItem, rightItem, leftItem, NULL);
moveItem->setPosition( CCPointZero );
this->addChild(moveItem, 0);
return true;
}
示例14: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
/////////////////////////////
// 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(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::create("Cocos2dx GreePlatform Binding Test", "Thonburi", 34);
// ask director the window size
CCSize size = CCDirector::sharedDirector()->getWinSize();
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
// add the label as a child to this layer
this->addChild(pLabel, 1);
// add "HelloWorld" splash screen"
pSprite = CCSprite::create("HelloWorld.png");
// position the sprite on the center of the screen
pSprite->setPosition( ccp(size.width/2, size.height/2) );
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
// GreeButton
pGreeButtonText = CCLabelTTF::create("Log in", "Thonburi", 34);
pGreeButtonText->setPosition(ccp(size.width - 100, size.height - 40));
this->addChild(pGreeButtonText, 1);
CCMenuItemImage *pGree = CCMenuItemImage::create("gree.png", "gree.png", this, menu_selector(HelloWorld::menuGreeButtonCallback));
pGree->setPosition(ccp(size.width - 100, size.height - 100));
CCMenu* pGreeMenu = CCMenu::create(pGree, NULL);
this->addChild(pGreeMenu, 1);
pGreeMenu->setPosition(CCPointZero);
pGree->setScaleY(3.0);
pGree->setScaleX(3.0);
return true;
}
示例15: init
bool OptionLayer::init()
{
if ( !CCLayer::init() )
{
return false;
}
// add options splash screen
CCSprite* pSprite = CCSprite::create("options_screen.jpg");
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
// position the sprite on the center of the screen
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
pSprite->setScaleY(visibleSize.height/pSprite->getContentSize().height);
// add the sprite as a child to this layer
this->addChild(pSprite);
//create option button
CCSprite *on= CCSprite::create("soundOn.png");
//create start button
CCSprite *off = CCSprite::create("soundOff.png");
//create the two items
CCMenuItemSprite *OnItem = CCMenuItemSprite::create(on, on, this, menu_selector(OptionLayer::turnSoundOn));
if(!OnItem) return false;
CCMenuItemSprite *OffItem = CCMenuItemSprite::create(off, off, this, menu_selector(OptionLayer::turnSoundOff));
if(!OffItem) return false;
//create menu
CCMenu* pMenu = CCMenu::create(OnItem, NULL);
if(!pMenu) return false;
CCMenu* pMenu2 = CCMenu::create(OffItem, NULL);
if(!pMenu2) return false;
//setup positioning
pMenu->setPosition(ccp(visibleSize.width/5.0, visibleSize.height/6.0));
//OptionItem->setPosition(ccp(visibleSize.width/4.0, visibleSize.height/6.0));
pMenu2->setPosition(ccp(visibleSize.width/2.0, visibleSize.height/6.0));
//StartItem->setPosition(ccp(visibleSize.width/3.0, visibleSize.height/4.0));
//pMenu->alignItemsHorizontallyWithPadding(300.0f);
//add menu item as layer
this->addChild(pMenu, 1);
this->addChild(pMenu2, 1);
volume1 = CocosDenshion::SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume();
volume2 = CocosDenshion::SimpleAudioEngine::sharedEngine()->getEffectsVolume();
// Create a back button
CCMenuItemImage *pCloseItem = CCMenuItemImage::create("back-button.png", "back-button.png", this, menu_selector(OptionLayer::BacktoMain));
// Place the menu item bottom-right conner.
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
origin.y + pCloseItem->getContentSize().height/2));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu3 = CCMenu::create(pCloseItem, NULL);
pMenu3->setPosition(CCPointZero);
// Add the menu to Option layer as a child layer.
this->addChild(pMenu3, 1);
return true;
}