Cocos2D-x game development-CCScale9Sprite and CCControlButton

Source: Internet
Author: User

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;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.