ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • cocos2d-x 메뉴전환정리
    Pause @/Cocos2d-x2 2013. 7. 7. 22:43

    void Game::initMenu()
    {
        CCMenuItemFont *item_0 = CCMenuItemFont::create("Retry", this, menu_selector(Game::menuCallback));
        CCMenuItemFont *item_1 = CCMenuItemFont::create("Menu", this, menu_selector(Game::menuCallback));
       
        item_0->setTag(0);
        item_1->setTag(1);
       
        CCMenu *pMenu = CCMenu::create(item_0, item_1, NULL);
        pMenu->alignItemsHorizontallyWithPadding(100);
        pMenu->setPosition(ccp(winSize.width/2, 30));
        pMenu->setTag(TAG_MENU);
        pMenu->setVisible(false);
        this->addChild(pMenu);
    }

    void Game::menuCallback(cocos2d::CCObject *pSender)
    {
        CCLog("menuCallback");
       
        CCMenuItemFont *item = (CCMenuItemFont *)pSender;
        int Tag = item->getTag();
       
        switch (Tag) {
            case 0:
            {
                initData();
               
                CCLabelTTF *pLabel_0 = (CCLabelTTF *)this->getChildByTag(TAG_LABEL_CARD);
                pLabel_0->setString("CARD : 0/4");
               
                CCLabelTTF *pLabel_1 = (CCLabelTTF *)this->getChildByTag(TAG_LABEL_LIFE);
                pLabel_1->setString("LIFE : 3");
               
                CCLabelTTF *pLabel_2 = (CCLabelTTF *)this->getChildByTag(TAG_LABEL_GAMECLEAR);
                pLabel_2->setPosition(ccp(winSize.width/2, winSize.height+50));
               
                CCLabelTTF *pLabel_3 = (CCLabelTTF *)this->getChildByTag(TAG_LABEL_GAMEOVER);
                pLabel_3->setPosition(ccp(winSize.width/2, winSize.height+50));
               
                CCMenu *pMenu = (CCMenu *)this->getChildByTag(TAG_MENU);
                pMenu->setVisible(false);
               
                actionReady();
            }
                break;
               
            case 1:
                CCDirector::sharedDirector()->replaceScene(Menu::scene());
                break;
               
            default:
                break;
        }
    }

     

    유의해서 볼것은, 저기 위에 menu_callback부분..

    그리고 pSender가 어떻게 되는지 봐야함..!

     

    'Pause @ > Cocos2d-x2' 카테고리의 다른 글

    cocos2d-x CCArray  (0) 2013.07.07
    cocos2d-x CCSpriteFrame & CCAnimaion & CCParalllaxnode  (0) 2013.07.07
    cocos2d-x 프로젝트1 정리  (0) 2013.07.03
    cocos2d-x 프로젝트 1  (0) 2013.07.03
    cocos2d-x 사운드 및  (0) 2013.06.30
Designed by Tistory.