本文整理汇总了C++中MenuItemSprite::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemSprite::setPosition方法的具体用法?C++ MenuItemSprite::setPosition怎么用?C++ MenuItemSprite::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItemSprite
的用法示例。
在下文中一共展示了MenuItemSprite::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
UI::UI( cocos2d::Layer *layer, int &gameState )
{
this->gameState = &gameState;
Size screenSize = Director::getInstance( )->getVisibleSize( );
Vec2 origin = Director::getInstance( )->getVisibleOrigin( );
MenuItemSprite *pauseItem = MenuItemSprite::create( Sprite::create( PAUSE_BUTTON ), Sprite::create( PAUSE_BUTTON_PRESSED ), Sprite::create( PAUSE_BUTTON_PRESSED ), CC_CALLBACK_1( UI::PauseGame, this ) );
pauseItem->setPosition( Vec2( screenSize.width - ( pauseItem->getContentSize( ).width / 2 ) + origin.x, screenSize.height - ( pauseItem->getContentSize( ).height / 2 ) + origin.y ) );
Menu *menuButtons = Menu::create( pauseItem, NULL );
menuButtons->setPosition( Vec2::ZERO );
layer->addChild( menuButtons );
pausebackground = Sprite::create( PAUSE_BACKGROUND );
pausebackground->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
pausebackground->setOpacity( 0 );
layer->addChild( pausebackground );
MenuItemImage *overlayPauseWindowItem = MenuItemImage::create( PAUSE_WINDOW, PAUSE_WINDOW, PAUSE_WINDOW, NULL );
MenuItemSprite *resumeItem = MenuItemSprite::create( Sprite::create( RESUME_BUTTON ), Sprite::create( RESUME_BUTTON_PRESSED ), Sprite::create( RESUME_BUTTON ), CC_CALLBACK_1( UI::PauseGame, this ) );
resumeItem->setPosition( Vec2( -overlayPauseWindowItem->getContentSize( ).width / 4, resumeItem->getPositionY( ) ) );
MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
mainMenuItem->setPosition( Vec2( overlayPauseWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
pauseMenu = Menu::create( overlayPauseWindowItem, resumeItem, mainMenuItem, NULL );
pauseMenu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
layer->addChild( pauseMenu );
}
示例2: ShowGameOver
void UI::ShowGameOver( cocos2d::Layer *layer )
{
Size screenSize = Director::getInstance( )->getVisibleSize( );
Sprite *background = Sprite::create( GAME_OVER_BACKGROUND );
background->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
background->setOpacity( 0 );
layer->addChild( background );
background->runAction( Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), FadeIn::create( GAME_OVER_BACKGROUND_FADE_IN_TIME ), NULL ) );
MenuItemImage *overlayWindowItem = MenuItemImage::create( GAME_OVER_WINDOW, GAME_OVER_WINDOW, GAME_OVER_WINDOW, NULL );
MenuItemSprite *retryItem = MenuItemSprite::create( Sprite::create( RETRY_BUTTON ), Sprite::create( RETRY_BUTTON_PRESSED ), Sprite::create( RETRY_BUTTON ), CC_CALLBACK_1( UI::Retry, this ) );
retryItem->setPosition( Vec2( overlayWindowItem->getContentSize( ).width / 4, retryItem->getPositionY( ) ) );
MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
mainMenuItem->setPosition( Vec2( -overlayWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
Menu *menu = Menu::create( overlayWindowItem, retryItem, mainMenuItem, NULL );
menu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
layer->addChild( menu );
EaseBounceOut *menuActionEasing = EaseBounceOut::create( MoveTo::create( MENU_MOVE_BOUNCE_DURATION, SonarCocosHelper::UI::GetScreenCenter( ) ) );
Sequence *menuShowSeq = Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), menuActionEasing, NULL );
menu->runAction( menuShowSeq );
}
示例3: createLayersContent
void ConfirmLayer::createLayersContent() {
GameModel* gameModel = GameModel::getInstance();
Face* backgroundFade = new Face();
backgroundFade->initWithFile(ANI_BACKGROUND_FADE);
backgroundFade->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
backgroundFade->setOpacity(0);
this->mainLayer->addChild(backgroundFade);
this->backgroundFade = backgroundFade;
{
FiniteTimeAction* fadeIn = FadeIn::create(0.5f);
backgroundFade->registerState(STATE_FADE_IN, fadeIn);
FiniteTimeAction* fadeOut = FadeOut::create(0.5f);
backgroundFade->registerState(STATE_FADE_OUT, fadeOut);
}
Face* menuFace = new Face();
menuFace->initWithSpriteFrameName(ANI_BOX_CONFIRM);
menuFace->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, -500));
this->mainLayer->addChild(menuFace);
this->menuFace = menuFace;
Size menuFaceSize = menuFace->getContentSize();
UGMenu* optionMenu = UGMenu::create();
optionMenu->setPosition(Point::ZERO);
menuFace->addChild(optionMenu);
{
Label* confirmLabel = Label::createWithBMFont(FONT_GAME_SMALL, TXT_CONFIRM_TEXT);
confirmLabel->setPosition(menuFaceSize.width / 2, menuFaceSize.height / 2);
this->menuFace->addChild(confirmLabel);
}
{
FiniteTimeAction* move1 = MoveTo::create(0, menuFace->getPosition());
FiniteTimeAction* move2 = MoveTo::create(0.5f, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
FiniteTimeAction* move3 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveUpDone, this));
FiniteTimeAction* move123 = Sequence::create(move1, move2, move3, NULL);
menuFace->registerState(STATE_MOVE_UP, move123);
FiniteTimeAction* move4 = MoveTo::create(0, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
FiniteTimeAction* move5 = MoveTo::create(0.5f, menuFace->getPosition());
FiniteTimeAction* move6 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveDownDone, this));
FiniteTimeAction* move456 = Sequence::create(move4, move5, move6, NULL);
menuFace->registerState(STATE_MOVE_DOWN, move456);
MenuItemSprite* okButton = Utils::createButton((char*) TXT_OK, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
okButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onOkButtonClick, this));
okButton->setPosition(Point(menuFaceSize.width / 2 - 129, 0));
okButton->setEnabled(false);
optionMenu->addChild(okButton);
this->okButton = okButton;
MenuItemSprite* cancelButton = Utils::createButton((char*) TXT_CANCEL, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
cancelButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onCancelButtonClick, this));
cancelButton->setPosition(Point(menuFaceSize.width / 2 + 129, 0));
cancelButton->setEnabled(false);
optionMenu->addChild(cancelButton);
this->cancelButton = cancelButton;
}
}
示例4: init
bool GameOverLayer::init(){
if(!Layer::init()){
return false;
}
Size MyWinSize = Director::getInstance()->getVisibleSize();
MenuItemSprite *reStartBtn = MenuItemSprite::create(Sprite::create("res/image/uires_5.png"),
Sprite::create("res/image/uires_5.png"),
NULL,
CC_CALLBACK_0(GameOverLayer::reStart,this)
);
MenuItemSprite *homeBtn = MenuItemSprite::create(Sprite::create("res/image/uires_8.png"),
Sprite::create("res/image/uires_8.png"),
NULL,
CC_CALLBACK_0(GameOverLayer::home,this)
);
reStartBtn->setPosition(MyWinSize.width/2+reStartBtn->getContentSize().width/2,MyWinSize.height/2 +8);
homeBtn->setPosition(MyWinSize.width/2-homeBtn->getContentSize().width/2,MyWinSize.height/2 +8);
Menu *menu = Menu::create(reStartBtn,homeBtn,NULL);
menu->setPosition(0,0);
this->addChild(menu);
return true;
}
示例5: addLayer
//pageview的用法
void TeachingLayer::addLayer(int index)
{
auto winSize = Director::getInstance()->getWinSize();
pageView = PageView::create();
//一定要设置大小,不然看不见
pageView->setContentSize(winSize);
pageView->setBackGroundColor(Color3B::GREEN);
pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
pageView->removeAllPages();
pageView->setPosition(Vec2::ZERO);
if (index == 0)
{
for (int i=0;i<4;++i)
{
//pageview一定要配合layout使用
Layout* layout = Layout::create();
layout->setContentSize(winSize);
auto layer = TeachingSubLayer::create(index,i);
//layer->setPosition(Vec2(winSize.width/2,winSize.height/2));
layout->addChild(layer);
//----按钮
MenuItemSprite* pJumpItem;
if (i<=2)
{
auto nextNormal = Sprite::create("teaching_next.png");
auto nextPressed = Sprite::create("teaching_next.png");
nextPressed->setScale(1.4f);
pJumpItem = MenuItemSprite::create(nextNormal,nextPressed,CC_CALLBACK_0(TeachingLayer::menuJump,this));
//pJumpItem->setPosition(Vec2(winSize.width/2 - 60,35-winSize.height/2));
pJumpItem->setPosition(Vec2(winSize.width - pJumpItem->getContentSize().width,
pJumpItem->getContentSize().height));
}
else//最后一步
{
auto nextNormal = Sprite::create("teaching_enter.png");
auto nextPressed = Sprite::create("teaching_enter.png");
nextPressed->setScale(1.4f);
pJumpItem = MenuItemSprite::create(nextNormal,nextPressed,CC_CALLBACK_0(TeachingLayer::menuJump,this));
pJumpItem->setPosition(Vec2(winSize.width - pJumpItem->getContentSize().width,
pJumpItem->getContentSize().height));
}
pJumpItem->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT);
auto pMenu = Menu::create(pJumpItem,nullptr);
pMenu->setPosition(Vec2::ZERO);
layer->addChild(pMenu,3);
pageView->insertPage(layout,i);
}
}
curPage = 0;
pageView->scrollToPage(curPage);
pageView->addEventListener(CC_CALLBACK_2(TeachingLayer::pageViewEvent, this));
this->addChild(pageView);
}
示例6: init
// on "init" you need to initialize your instance
bool MainMenu::init()
{
if ( !Layer::init() )
{
return false;
}
Sprite* background = Sprite::create("mainbg.jpg");
background->setPosition(SCREEN_SIZE.width/2, SCREEN_SIZE.height/2);
setScale(SCREEN_SIZE.width/background->getContentSize().width,
SCREEN_SIZE.height/background->getContentSize().height);
addChild(background);
Sprite* normalS = Sprite::create("startButton.png");
Sprite* selectedS = Sprite::create("startButton.png");
selectedS->setColor(Color3B::GRAY);
MenuItemSprite* start = MenuItemSprite::create(normalS,
selectedS,
CC_CALLBACK_1(MainMenu::goToStartScene, this));
Point posStart = Point(SCREEN_SIZE.width/2, SCREEN_SIZE.height/4 + 10);
start->setPosition(posStart);
start->setScale(0.5f);
Sprite* normalE = Sprite::create("emergencyButton.png");
normalE->setColor(Color3B::RED);
Sprite* selectedE = Sprite::create("emergencyButton.png");
selectedE->setColor(Color3B::GRAY);
MenuItemSprite* emergency = MenuItemSprite::create(normalE,
selectedE,
CC_CALLBACK_1(MainMenu::goToStartScene, this));
Point posEmer = Point(SCREEN_SIZE.width/3 + 10, SCREEN_SIZE.height/4 + 10);
emergency->setPosition(posEmer);
emergency->setScale(0.5f);
Sprite* normalSe = Sprite::create("settingButton.png");
Sprite* selectedSe = Sprite::create("settingButton.png");
selectedSe->setColor(Color3B::GRAY);
MenuItemSprite* settings = MenuItemSprite::create(normalSe,
selectedSe,
CC_CALLBACK_1(MainMenu::goToStartScene, this));
Point posSe = Point(2 * SCREEN_SIZE.width/3 - 10, SCREEN_SIZE.height/4 + 10);
settings->setPosition(posSe);
settings->setScale(0.5f);
Menu* menu = Menu::create(start, emergency, settings, NULL);
menu->setPosition(Point::ZERO);
addChild(menu, 1);
return true;
}
示例7: showResult
void HelloWorld::showResult() {
Size visibleSize = Director::getInstance()->getVisibleSize();
//add black cover
blackLayer = LayerColor::create(Color4B(0, 0, 0, 120));
blackLayer->setContentSize(visibleSize);
blackLayer->setPosition(0,0);
addChild(blackLayer);
cool = Label::createWithSystemFont("COOL!", "Hobo std", 90);
cool->setPosition(visibleSize.width/2, visibleSize.height*2/3);
this->addChild(cool);
moon->setSpriteFrame("MoonCry.png");
//Play again button
Sprite* PlayAgainButton = Sprite::createWithSpriteFrameName("ReplayButton.png");
MenuItemSprite* PlayButtonItem = MenuItemSprite::create(PlayAgainButton, PlayAgainButton,
CC_CALLBACK_1(HelloWorld::playAgainCallBack, this));
PlayButtonItem->setPosition(Director::getInstance()->convertToGL(Vec2(visibleSize.width/2-100, visibleSize.height*3/4)));
//add all items into setMenu
playAgainMenu = Menu::create(PlayButtonItem, NULL);
playAgainMenu->setPosition(Vec2::ZERO);
this->addChild(playAgainMenu);
}
示例8: init
bool BowManHightScore::init()
{
if(!Layer::init()){
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Sprite* backSprite1 = Sprite::create("img/button/back_btn.png");
Sprite* backSprite2 = Sprite::create("img/button/back_btn1.png");
MenuItemSprite* backBtn = MenuItemSprite::create(
backSprite1 ,
backSprite2 ,
CC_CALLBACK_1(BowManHightScore::backCallback , this)
);
backBtn->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
backBtn->setPosition(Vec2(
10 + backBtn->getContentSize().width/2 ,
visibleSize.height - 10 - backBtn->getContentSize().height/2
));
Menu* menu = Menu::create(
backBtn,
NULL
);
this->addChild(menu);
return true;
}
示例9: init
bool BowManInforGame::init()
{
if(!Layer::init())
{
return false;
}
/////////////////////////////////////////////////////////////////
// BACKGROUNG INFO
/////////////////////////////////////////////////////////////////
Sprite* background = Sprite::create("img/background/bg_info.png");
background->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
background->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2));
this->addChild(background);
/////////////////////////////////////////////////////////////////
// DIALOG INFO
/////////////////////////////////////////////////////////////////
Sprite* infoDialog = Sprite::create("img/dialog/info_dialog.png");
infoDialog->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
infoDialog->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2));
this->addChild(infoDialog);
/////////////////////////////////////////////////////////////////
// BACK BUTTON
/////////////////////////////////////////////////////////////////
Sprite* backSprite1 = Sprite::create("img/button/back_btn.png");
Sprite* backSprite2 = Sprite::create("img/button/back_btn1.png");
MenuItemSprite* backBtn = MenuItemSprite::create(
backSprite1,
backSprite2,
CC_CALLBACK_1(BowManInforGame::backCallback, this)
);
backBtn->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
backBtn->setPosition(Vec2(
10 + backBtn->getContentSize().width / 2,
WINSIZE.height - 10 - backBtn->getContentSize().height / 2
));
Menu* menu = Menu::create(backBtn,NULL);
this->addChild(menu);
return true;
}
示例10: log
// on "init" you need to initialize your instance
bool MusicLayer_2::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
log("MusicLayer_2 init");
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Sprite *bg = Sprite::create("background.png");
// position the label on the center of the screen
bg->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height /2));
this->addChild(bg);
//开始精灵
Sprite *startSpriteNormal = Sprite::create("start-up.png");
Sprite *startSpriteSelected = Sprite::create("start-down.png");
MenuItemSprite *startMenuItem = MenuItemSprite::create(startSpriteNormal,
startSpriteSelected,
CC_CALLBACK_1(MusicLayer_2::menuItemStartCallback, this));
startMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(700, 170)));
// 设置图片菜单
MenuItemImage *settingMenuItem = MenuItemImage::create(
"setting-up.png",
"setting-down.png",
CC_CALLBACK_1(MusicLayer_2::menuItemSettingCallback, this));
settingMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(480, 400)));
// 帮助图片菜单
MenuItemImage *helpMenuItem = MenuItemImage::create(
"help-up.png",
"help-down.png",
CC_CALLBACK_1(MusicLayer_2::menuItemHelpCallback, this));
helpMenuItem->setPosition(Director::getInstance()->convertToGL(Vec2(860, 480)));
Menu* mu = Menu::create(startMenuItem, settingMenuItem, helpMenuItem, NULL);
mu->setPosition(Vec2::ZERO);
this->addChild(mu);
return true;
}
示例11: updateBigBoomCount
void LayerGameMain::updateBigBoomCount(int bigBoomCount)
{
String strBoomCount;
Sprite * norBoom = Sprite::createWithSpriteFrameName("bomb.png");
Sprite * selBoom = Sprite::createWithSpriteFrameName("bomb.png");
if (bigBoomCount < 0)
{
return;
}
else if (bigBoomCount == 0)
{
if (this->getChildByTag(TAG_BIGBOOM))
{
this->removeChildByTag(TAG_BIGBOOM,true);
}
if (this->getChildByTag(TAG_BIGBOOMCOUNT))
{
this->removeChildByTag(TAG_BIGBOOMCOUNT,true);
}
}
else if (bigBoomCount == 1)
{
if ( !(this->getChildByTag(TAG_BIGBOOM)) )
{
MenuItemSprite * boomItem = MenuItemSprite::create(norBoom,
selBoom,
CC_CALLBACK_1(LayerGameMain::boomMenuCallback,this));
boomItem->setPosition(norBoom->getContentSize().width/2,norBoom->getContentSize().height/2);
Menu * boomMenu = Menu::create(boomItem,nullptr);
boomMenu->setPosition(Point::ZERO);
this->addChild(boomMenu,0,TAG_BIGBOOM);
}
if ( !(this->getChildByTag(TAG_BIGBOOMCOUNT)) )
{
strBoomCount.initWithFormat("X %d",bigBoomCount);
LabelBMFont * labelBoomCount = LabelBMFont::create(strBoomCount.getCString(),"font/font.fnt");
labelBoomCount->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
labelBoomCount->setPosition(Point(norBoom->getContentSize().width,norBoom->getContentSize().height - 30));
this->addChild(labelBoomCount,0,TAG_BIGBOOMCOUNT);
}
}
else if (bigBoomCount > 1 && bigBoomCount < MAX_BIGBOOM_COUNT)
{
strBoomCount.initWithFormat("X %d",bigBoomCount);
LabelBMFont * labelCount = (LabelBMFont *)this->getChildByTag(TAG_BIGBOOMCOUNT);
labelCount->setString(strBoomCount.getCString());
}
}
示例12: addButton
bool DialogLayer::addButton(const char* title, Sprite* normalImage, Sprite* selectedImage, Sprite* disableImage, const ccMenuCallback& callback, int tag/* =0 */)
{
Size winSize = Director::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
// 创建图片菜单按钮
MenuItemSprite* menuImage = MenuItemSprite::create(normalImage, selectedImage, disableImage, callback);
menuImage->setTag(tag);
menuImage->setPosition(pCenter);
// 添加文字说明并设置位置
Size imenu = menuImage->getContentSize();
LabelTTF* ttf = CCLabelTTF::create(title, "Arial", 25);
ttf->setColor(Color3B(0, 0, 0));
ttf->setPosition(imenu.width / 2, imenu.height / 2);
menuImage->addChild(ttf);
getMenuButton()->addChild(menuImage);
return true;
}
示例13: createLayersContent
void LevelScene::createLayersContent() {
Size winSize = Director::getInstance()->getWinSize();
// create background
CSprite* backgroundFace = new CSprite();
backgroundFace->initWithFile(FRAME_BG);
backgroundFace->setPosition(winSize.width / 2, winSize.height / 2);
this->backgroundLayer->addChild(backgroundFace);
// create level title
CSprite* chapterTitle = new CSprite();
chapterTitle->initWithSpriteFrameName(FRAME_LEVEL_TITLE);
chapterTitle->setPosition(winSize.width / 2, winSize.height - chapterTitle->getContentSize().height / 2 - 20);
this->mainLayer->addChild(chapterTitle);
// create menu
Menu* mainMenu = Menu::create();
mainMenu->setPosition(Point::ZERO);
this->mainLayer->addChild(mainMenu);
// create back button
MenuItemSprite* backButton = CNodeUtil::createButton(FRAME_BACK_BUTTON, FRAME_BACK_BUTTON_SELECTED);
backButton->setCallback(CC_CALLBACK_1(LevelScene::backButtonClick, this));
backButton->setPosition(winSize.width / 2, 20 + backButton->getContentSize().height / 2);
mainMenu->addChild(backButton);
// create level layer
this->levelLayer = Layer::create();
int levelTotal = CONFIG_LEVELS_PER_CHAPTER;
int totalPageSize = ((levelTotal - 1) / CONF_TOTAL_LEVEL_SIZE_PER_PAGE) + 1;
int levelPerPage = CONF_TOTAL_LEVEL_SIZE_PER_PAGE;
int levelPerRow = levelPerPage / CONF_TOTAL_LEVEL_ROW;
int previousLevelTotal = this->getTotalPreviousLevel(this->currentChapter);
this->levelLayer->setContentSize(Size(winSize.width * totalPageSize, winSize.height / 1.5));
this->levelLayer->setPosition(0, winSize.height / 2 - this->levelLayer->getContentSize().height / 2);
this->levelLayerOffset = this->levelLayer->getPosition();
this->mainLayer->addChild(this->levelLayer);
for (int i = 0; i < levelTotal; i++) {
int level = i + 1;
CSprite* levelFace = new CSprite();
int realLevel = level + previousLevelTotal;
// if (gameModel->checkMapLock(realLevel)) {
levelFace->initWithSpriteFrameName(FRAME_BOX_LEVEL);
levelFace->setTag(realLevel);
{
char levelChar[10];
sprintf(levelChar, "%d", level);
Label* levelLabel = CNodeUtil::createLabelTTF(levelChar, 12);
levelLabel->setPosition(levelFace->getContentSize().width / 2, levelFace->getContentSize().height / 2);
levelFace->addChild(levelLabel);
}
// } else {
// levelFace->initWithSpriteFrameName(ANI_BOX_MAP_LOCK);
// levelFace->setTag(-1);
// }
this->levelLayer->addChild(levelFace);
int page = i / levelPerPage;
int row = ((level - (page * levelPerPage)) - 1) / levelPerRow;
int column = i % levelPerRow;
Point pagePosition = Point(winSize.width * page, 0);
float totalWidth = levelFace->getContentSize().width * levelPerRow + (10 * (levelPerRow + 1));
float totalHeight = levelFace->getContentSize().height * CONF_TOTAL_LEVEL_ROW + (10 * (CONF_TOTAL_LEVEL_ROW + 1));
float initX = (winSize.width - totalWidth) / 2;
float initY = this->levelLayer->getContentSize().height - ((this->levelLayer->getContentSize().height - totalHeight) / 2);
float levelPositionX = initX + (10 * (column + 1)) + (levelFace->getContentSize().width / 2 * (column + 1)) + (levelFace->getContentSize().width / 2 * column);
float levelPositionY = initY - (10 * (row + 1)) - (levelFace->getContentSize().height / 2 * (row + 1)) - (levelFace->getContentSize().height / 2 * row);
levelFace->setPosition(Point(levelPositionX, levelPositionY) + pagePosition);
}
}
示例14: createLayersContent
void ChapterScene::createLayersContent() {
GameModel* gameModel = GameModel::getInstance();
Size displayResolutionSize = gameModel->getDisplayResolutionSize();
Face* backgroundFace = new Face();
backgroundFace->initWithFile(ANI_BACKGROUND);
backgroundFace->setScale(CONF_FAKE_1);
backgroundFace->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height / 2);
this->backgroundLayer->addChild(backgroundFace);
Face* chapterTitle = new Face();
chapterTitle->initWithSpriteFrameName(ANI_CHAPTER_TITLE);
chapterTitle->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height - chapterTitle->getContentSize().height / 2 - 20);
this->mainLayer->addChild(chapterTitle);
UGMenu* mainMenu = UGMenu::create();
mainMenu->setPosition(Point::ZERO);
this->mainLayer->addChild(mainMenu);
MenuItemSprite* backButton = Utils::createButton((char*) TXT_BACK, 16, ANI_BUTTON, ANI_BUTTON);
backButton->setCallback(CC_CALLBACK_1(ChapterScene::backButtonClick, this));
backButton->setPosition(gameModel->getDisplayResolutionSize().width / 2, 20 + backButton->getContentSize().height / 2);
mainMenu->addChild(backButton);
this->nodes->setObject(backButton, NODE_BUTTON_BACK);
// create chapters
this->chapterLayer = UGLayerColor::create();
float totalChapterSize = gameModel->getMapData()->getLevelSize();
float distancePerChapter = CONF_DISTANCE_PER_CHAPTER;
float totalChapterWidth = (totalChapterSize - 1) * distancePerChapter;
Face* chapterTemp = new Face();
chapterTemp->initWithSpriteFrameName(ANI_BOX_CHAPTER);
this->chapterTempSize = chapterTemp->getContentSize();
this->chapterLayer->setContentSize(Size(totalChapterWidth + this->chapterTempSize.width, displayResolutionSize.height / 2));
this->chapterLayer->setPosition(displayResolutionSize.width / 2 - this->chapterTempSize.width / 2, displayResolutionSize.height / 2 - this->chapterLayer->getContentSize().height / 2);
this->chapterLayerOffset = this->chapterLayer->getPosition();
this->mainLayer->addChild(this->chapterLayer);
float posX = this->chapterTempSize.width / 2;
float posY = this->chapterLayer->getContentSize().height / 2;
for (int i = 0; i < totalChapterSize; i++) {
Face* levelBox = new Face();
if (!gameModel->checkLevelLock(i + 1)) {
levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER);
levelBox->setTag(i + 1);
{
int chapter = gameModel->getMapData()->getChapter(i + 1);
int chapterLevel = gameModel->getMapData()->getChapterLevel(i + 1);
char mapPath[200];
sprintf(mapPath, DOC_BG_MAP, chapter, chapterLevel);
SpriteFrameCache* sfc = SpriteFrameCache::getInstance();
sfc->addSpriteFramesWithFile(mapPath);
char bg1Path[200];
sprintf(bg1Path, ANI_MAP, chapter, chapterLevel, 1);
Face* chapterThumb = new Face();
chapterThumb->initWithSpriteFrameName(bg1Path);
chapterThumb->setPosition(levelBox->getContentSize().width / 2, levelBox->getContentSize().height / 2 - 10);
chapterThumb->setTextureRect(Rect(0, 0, 160, 115));
levelBox->addChild(chapterThumb);
string levelName = gameModel->getMapData()->getLevelName(i + 1);
char levelNameChar[200];
sprintf(levelNameChar, "%s", levelName.data());
Label* levelNameLabel = Label::createWithBMFont(FONT_GAME_SMALL, levelNameChar);
levelNameLabel->setPosition(chapterThumb->getPosition() + Point(0, chapterThumb->getContentSize().height / 2 + 12));
levelBox->addChild(levelNameLabel);
}
} else {
levelBox->setTag(-1);
levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER_LOCK);
}
levelBox->setPosition(posX, posY);
posX = posX + distancePerChapter;
this->chapterLayer->addChild(levelBox);
}
// add parent button for share layer
this->shareLayer->getParentButtons()->pushBack((MenuItemSprite*) this->nodes->objectForKey(NODE_BUTTON_BACK));
}
示例15: init
bool ChoseLevel::init(PhysicsWorld* world){
if (!Layer::init()){
return false;
}
m_world = world;
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
if (!database->getBoolForKey("isExit")){
database->setBoolForKey("isExit", true);
database->setIntegerForKey("nowLevel",0);
database->setIntegerForKey("nowStage",0);
level = 0;
stage = 0;
}
else{
level = database->getIntegerForKey("nowLevel");
stage = database->getIntegerForKey("nowStage");
}
Sprite* bgImage = Sprite::create("images/bg.png");
bgImage->setPosition(visibleSize.width/2, visibleSize.height/2);
this->addChild(bgImage,1);
auto homeItem = MenuItemImage::create("images/home.png","images/home.png",CC_CALLBACK_0(ChoseLevel::backHome,this));
auto homeMenu = Menu::createWithItem(homeItem);
this->addChild(homeMenu,5);
homeMenu->setPosition(visibleSize.width-homeItem->getContentSize().width/2, visibleSize.height-homeItem->getContentSize().height/2);
//auto levelOne = MenuItemLabel::create(Label::createWithTTF("Zero","fonts/arial.ttf",40),
// CC_CALLBACK_0(ChoseLevel::selectLevel,this,0));
//levelOne->setPosition(-2*levelOne->getContentSize().width,0);
//auto levelTwo = MenuItemLabel::create(Label::createWithTTF("One", "fonts/arial.ttf", 40),
// CC_CALLBACK_0(ChoseLevel::selectLevel, this, 1));
//levelTwo->setPosition(0,0);
//auto levelThree = MenuItemLabel::create(Label::createWithTTF("Two", "fonts/arial.ttf", 40),
// CC_CALLBACK_0(ChoseLevel::selectLevel, this, 2));
//levelThree->setPosition(2 * levelThree->getContentSize().width, 0);
//auto choseMenu = Menu::create(levelOne,levelTwo,levelThree,NULL);
//choseMenu->setPosition(visibleSize.width/2,visibleSize.height/2);
//this->addChild(choseMenu,2);
auto menuBg = Sprite::create("images/scroll.png");
menuBg->setPosition(visibleSize.width/2, visibleSize.height/2);
this->addChild(menuBg,2);
Vector<MenuItem*> levels;
MenuItemSprite* levelItem;
/*
for (int i = 0; i < unlock; i++){
auto normalSprite = Sprite::create("images/levelImage.png");
auto selectedSprite = Sprite::create("images/levelImage.png");
selectedSprite->setOpacity(200);
levelItem = MenuItemSprite::create(normalSprite, selectedSprite, CC_CALLBACK_0(ChoseLevel::selectLevel,this,i));
levelItem->setPosition(i*levelItem->getContentSize().width*3/2,0);
auto levelStr = String::createWithFormat("%d",i+1);
auto levelLabel = Label::createWithTTF(levelStr->getCString(),"fonts/arial.ttf",40);
levelLabel->setPosition(levelItem->getContentSize().width/2, levelItem->getContentSize().height/2);
levelItem->addChild(levelLabel);
levels.pushBack(levelItem);
}*/
int count = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++){
auto normalSprite = Sprite::create("images/levelImage.png");
auto selectedSprite = Sprite::create("images/levelImage.png");
selectedSprite->setOpacity(200);
levelItem = MenuItemSprite::create(normalSprite, selectedSprite);
levelItem->setPosition(i*levelItem->getContentSize().width*3/2, -j*levelItem->getContentSize().height*3/2);
if (count <= level){
levelItem->setCallback(CC_CALLBACK_0(ChoseLevel::selectLevel, this, count));
auto levelStr = String::createWithFormat("%d", count + 1);
auto levelLabel = Label::createWithTTF(levelStr->getCString(), "fonts/arial.ttf", 40);
levelLabel->setPosition(levelItem->getContentSize().width / 2, levelItem->getContentSize().height / 2);
levelItem->addChild(levelLabel);
count++;
}
else{
auto lock = Sprite::create("images/locked.png");
lock->setPosition(levelItem->getContentSize().width / 2, levelItem->getContentSize().height / 2);
levelItem->addChild(lock);
}
levels.pushBack(levelItem);
}
}
auto levelMenu = Menu::createWithArray(levels);
levelMenu->setPosition(visibleSize.width / 2 - levelItem->getContentSize().width * 3 / 2, visibleSize.height / 2 + levelItem->getContentSize().width/10*7);
this->addChild(levelMenu,3);
return true;
}