Cocos2D-x游戏开发之四:CCScale9Sprite and CCControlButton

接着描述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;
}


Cocos2D-x游戏开发之四:CCScale9Sprite and CCControlButton_第1张图片

你可能感兴趣的:(Cocos2D-x游戏开发之四:CCScale9Sprite and CCControlButton)