Cocos2D-x遊戲開發之CCScale9Sprite and CCControlButton

來源:互聯網
上載者:User

接著描述Cocos2D-x基礎知識。這一節我描述一下Cocos2D-x的CCScale9Sprite and CCControlButton 用法。

先上代碼吧,我們直接在helloworld的init函數中做更改調試:


bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////


        CC_BREAK_IF(! CCLayer::init());


        //////////////////////////////////////////////////////////////////////////
        // add your codes below...
        //////////////////////////////////////////////////////////////////////////


        // 1. Add a menu item with "X" image, which is clicked to quit the program.


        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png","CloseSelected.png",this, menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);
        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));


        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);


        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);




        // 3. Add add a splash screen, show the cocos2d splash image.
        CCScale9Sprite* pSprite = CCScale9Sprite::create("HelloWorld.png");
        CCScale9Sprite* pSprite1 = CCScale9Sprite::create("HelloWorld1.png");
CCLabelTTF *tittle = CCLabelTTF::create("touch me","Marker Felt",60);
CCControlButton *button = CCControlButton::create(tittle,pSprite);
button->setBackgroundSpriteForState(pSprite1,CCControlStateSelected);
button->setPosition(ccp(size.width/2, size.height/2));
        this->addChild(button, 0);


        bRet = true;
    } while (0);


    return bRet;
}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.