Then describe the basic knowledge of Cocos2D-x. This section describes the usage of CCScale9Sprite and CCControlButton in the Cocos2D-x.
Let's start with the code. We can directly debug the changes in the init function of helloworld:
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: shareddire()-> 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 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;
}