本文整理汇总了C++中CCMenu::setPositionX方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenu::setPositionX方法的具体用法?C++ CCMenu::setPositionX怎么用?C++ CCMenu::setPositionX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenu
的用法示例。
在下文中一共展示了CCMenu::setPositionX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMenu
void CMenuLayer::createMenu()
{
CCMenuItemFont::setFontSize( 32 );
CCMenuItemFont::setFontName("Courier New");
setTouchEnabled(true);
// Font Item
CCMenuItem* quit = CCMenuItemImage::create( "images/CloseNormal.png", "images/CloseSelected.png", this, menu_selector(CMenuLayer::onQuit) );
CCMenu* menu = CCMenu::create( quit, NULL);
menu->alignItemsVertically();
addChild( menu );
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCSize itemSize = quit->getContentSize();
menu->setPositionX( winSize.width - itemSize.width / 2 );
menu->setPositionY( winSize.height - itemSize.height / 2 );
}
示例2: onShow
void ChallengeAgainLayer::onShow(int round, int need)
{
float totalWidth = 0.0;
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *app1 = CCSprite::create(g_sRelifeBGImage);
app1->setAnchorPoint(ccp(0,0));
app1->setPositionX(30);
app1->setPositionY(s.height*0.5);
this->addChild(app1);
totalWidth += app1->getContentSize().width;
NumberSprite * roundTip = NumberSprite::create("green60",round);
roundTip->setAnchorPoint(ccp(0,0));
roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
roundTip->setPositionY(app1->getPositionY());
this->addChild(roundTip);
totalWidth += 4;
totalWidth += roundTip->realWidth;
CCSprite *app2 = CCSprite::create(g_sGuanBGImage);
app2->setAnchorPoint(ccp(0,0));
app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);
app2->setPositionY(roundTip->getPositionY());
this->addChild(app2);
totalWidth += 4;
totalWidth += app2->getContentSize().width;
float bx = (s.width - totalWidth)*0.5;
app1->setPositionX(bx);
roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4);
app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4);
CCSprite *app3 = CCSprite::create(g_sLifeNeedBGImage);
app3->setAnchorPoint(ccp(0,0));
app3->setPositionX(app1->getPositionX());
app3->setPositionY(app2->getPositionY()-app2->getContentSize().height-20);
this->addChild(app3);
NumberSprite * needTip = NumberSprite::create("green60",need);
needTip->setAnchorPoint(ccp(0,0));
needTip->setPositionX(app3->getPositionX()+app3->getContentSize().width+4);
needTip->setPositionY(app3->getPositionY());
this->addChild(needTip);
CCSprite *app4 = CCSprite::create(g_sLifeValueBGImage);
app4->setAnchorPoint(ccp(0,0));
app4->setPositionX(needTip->getPositionX()+needTip->realWidth+4);
app4->setPositionY(needTip->getPositionY());
this->addChild(app4);
CCMenuItemImage* pSureMenu = CCMenuItemImage::create(
g_sSureBGImage,
g_sSureBGImage,
this,
menu_selector(ChallengeAgainLayer::onCommandSure));
pSureMenu->setAnchorPoint(ccp(0,0));
CCMenu* pMenu = CCMenu::create(pSureMenu, NULL);
this->addChild(pMenu);
pMenu->setTouchPriority(-1000);
pMenu->setAnchorPoint(ccp(0,0));
pMenu->setPositionY(app4->getPositionY()-app4->getTextureRect().size.height-40);
pMenu->setPositionX(100);
CCSprite * img = CCSprite::create(g_sReturnBGImage);
CCMenuItemImage* pReturnMenu = CCMenuItemImage::create(
g_sReturnBGImage,
g_sReturnBGImage,
this,
menu_selector(ChallengeAgainLayer::onCommandReturn));
pReturnMenu->setAnchorPoint(ccp(0,0));
CCMenu* pMenu2 = CCMenu::create(pReturnMenu, NULL);
this->addChild(pMenu2);
pMenu2->setTouchPriority(-1000);
pMenu2->setAnchorPoint(ccp(0,0));
pMenu2->setPositionY(pMenu->getPositionY());
pMenu2->setPositionX(s.width-img->getTextureRect().size.width-100);
}
示例3: init
// on "init" you need to initialize your instance
bool TestAircraft::init()
{
if ( !CCLayer::init() )
{
return false;
}
// ------------
// init input manager
// ---------------
InputManager* input = InputManager::sharedInstance();
CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(input);
// -------------
// init physics
// -----------
PhysicsManager::sharedInstance()->enableDebugDraw(true);
GB2ShapeCache::sharedGB2ShapeCache()->addShapesWithFile("png/physics.plist");
// step
schedule(schedule_selector(TestAircraft::stepForPhysicsManager));
// -----------------
// Init Audio
// ------------
SimpleAudioEngine::sharedEngine()->preloadEffect("wav/exploStd.wav");
// ------------
// Hero Aircraft
// -----------
Aircraft* hero = Aircraft::createHeroAircraft();
addChild(hero);
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
hero->setPosition(screenSize.width/2, screenSize.height/2);
GameController::sharedInstance()->setPlayerAircraft(hero);
// ------------
// create menu
// -------------
CCMenu* menu = CCMenu::create();
// straight menu item
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("straight", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// omni
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("omni", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// ray gun
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("ray gun", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// tank
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("tank", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// boss00
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("boss00", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// boss01
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("boss01", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
// hero
{
CCMenuItemFont* menuItem = CCMenuItemFont::create("hero", this, menu_selector(TestAircraft::menuItemCallback));
menu->addChild(menuItem);
}
menu->alignItemsVertically();
addChild(menu);
menu->setPositionX(menu->getPositionX() + 200);
return true;
}
示例4: init
bool SelectLevel::init()
{
if(!SceneStyle::init())
return false;
ADSoundManager::playMusic(InfoStyles::MENU_MUSIC);
//Get curren collection
const Collection* current_collection;
current_collection =LevelSaves::getInstance().getCollectionById(
_collection_id);
//Get the screen start of cordinates
const CCPoint ORIGIN = ADScreen::getOrigin();
const CCSize VISIBLE_SIZE = ADScreen::getVisibleSize();
const float SCALE = ADScreen::getScaleFactor();
float x_middle_of_sheet = (VISIBLE_SIZE.width-133/SCALE)/2 + ORIGIN.x;
float padding = 25/SCALE;
showBackground(BackgroundType::Dark);
showButtonBack();
//window title
cocos2d::CCLabelTTF* title_select_collection;
title_select_collection = CCLabelTTF::create(current_collection->getName().c_str(),
ADLanguage::getFontName(),
InfoStyles::SIZE_MENU_TITLE);
title_select_collection->setPositionX(x_middle_of_sheet+padding*2);
title_select_collection->setPositionY(ORIGIN.y +
+ VISIBLE_SIZE.height-padding*0.25f -
title_select_collection->getContentSize().height*0.5f);
title_select_collection->setColor(InfoStyles::COLOR_WHITE);
this->addChild(title_select_collection);
//menu
CCMenu* menu =CCMenu::create();
float position_menu_y = VISIBLE_SIZE.height -padding*0.25f -
title_select_collection->getContentSize().height*0.5f;
float collection_width = 0;
float card_height = 0;
float card_width = 0;
int current_dificult;
current_dificult = 0;
for(unsigned int j = 0; j < 3; ++j)
{
current_dificult = j;
Card* card;
if (j == 0)
{
int star_number = SaveStarsManager::getInstance()->getStars(
_collection_id, j);
card = Card::create(CCSprite::create(current_collection->getCollectionPartEasy().getImage().c_str()),
_("select_level.easy"),
star_number,CardType::WithBorder);
}
else if (j == 1)
{
int star_number = SaveStarsManager::getInstance()->getStars(
_collection_id, j);
card = Card::create(CCSprite::create(current_collection->getCollectionPartMiddle().getImage().c_str()),
_("select_level.middle"),
star_number,CardType::WithBorder);
}
else if (j == 2)
{
int star_number = SaveStarsManager::getInstance()->getStars(
_collection_id, j);
card = Card::create(CCSprite::create(current_collection->getCollectionPartDifficult().getImage().c_str()),
_("select_level.difficult"),
star_number,CardType::WithBorder);
}
ADMenuItem* button_card = ADMenuItem::create(card);
button_card->setAnchorPoint(ccp(0.5f,0.5f));
float one_card_width = 340/SCALE;
collection_width += one_card_width;
card_height = button_card->getContentSize().height;
card_width = button_card->getContentSize().width;
button_card->setPositionY(ORIGIN.y+button_card->getContentSize().height*0.5f);
button_card->setPositionX(one_card_width*j + button_card->getContentSize().width*0.5f);
CollectionID id = current_collection->getID();
button_card->setClickAction([id,current_dificult](){
CCDirector::sharedDirector()->replaceScene(LevelScene::scene(id,current_dificult));
});
menu->addChild(button_card);
card->setCardColor(LevelSaves::getInstance().getColor(_collection_id));
//.........这里部分代码省略.........