Cocos2d-x3.2 LayerMultiplex instructions for use

Source: Internet
Author: User

Cocos2d-x3.2 LayerMultiplex instructions for use

LayerMultiplex is the layer controller class

Use the following

LayerMultiplexTest. h

//// LayerMultiplexTest. h // cpp4 // Created by du jia on 10/13/14. /// # ifndef _ cpp4 _ LayerMultiplexTest __# define _ cpp4 _ LayerMultiplexTest __# include "cocos2d. h "USING_NS_CC; class LayerMultiplexTest: public Layer {public: virtual bool init (); // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d: Scene * scene (); // implement the "static node ()" method manually CREATE_FUNC (LayerMultiplexTest);}; class TestMainLayer: public LayerColor {public: virtual bool init (); CREATE_FUNC (TestMainLayer); private: void menuCallback1 (cocos2d: Ref * sender); void menuCallback2 (cocos2d :: ref * sender) ;}; class TestLayer1: public LayerColor {public: virtual bool init (); CREATE_FUNC (TestLayer1); void menuCallback1 (cocos2d: Ref * sender );}; class TestLayer2: public LayerColor {public: virtual bool init (); CREATE_FUNC (TestLayer2); void menuCallback1 (cocos2d: Ref * sender );}; # endif/* defined (_ cpp4 _ LayerMultiplexTest __)*/

LayerMultiplexTest. cpp


//// LayerMultiplexTest. cpp // cpp4 // Created by du jia on 10/13/14. //// # include "LayerMultiplexTest. h "Scene * LayerMultiplexTest: scene () {// 'Scene 'is an autorelease object auto scene = scene: create (); // 'lay' is an autorelease object LayerMultiplexTest * layer = LayerMultiplexTest: create (); // add layer as a child to scene-> addChild (layer ); // return the scene return scene;} bool LayerMult IplexTest: init () {bool bRet = false; do {CC_BREAK_IF (! Layer: init (); auto mainLayer = TestMainLayer: create (); auto layer1 = TestLayer1: create (); auto layer2 = TestLayer2: create (); // Add layers to LayerMultiplex auto layerMutiplex = LayerMultiplex: create (mainLayer, layer1, layer2, nullptr); addChild (layerMutiplex, 0); bRet = true ;} while (0); return bRet;} bool TestMainLayer: init () {bool bRet = false; do {CC_BREAK_IF (! LayerColor: init (); auto winSize = Director: getInstance ()-> getWinSize (); auto label1 = Label: createWithBMFont ("bitmapFontTest3.fnt ", "TestLayer 1"); auto item1 = MenuItemLabel: create (label1, CC_CALLBACK_1 (TestMainLayer: menuCallback1, this); auto label2 = Label: createWithBMFont ("bitmapFontTest3.fnt ", "TestLayer 2"); auto item2 = MenuItemLabel: create (label2, CC_CALLBACK_1 (TestMainLayer: menuCallback2, this); auto menu = Menu: create (item1, item2, NULL); menu-> alignItemsVertically (); menu-> setPosition (winSize/2); addChild (menu); bRet = true;} while (0); return bRet ;} void TestMainLayer: menuCallback1 (cocos2d: Ref * sender) {static_cast
 
  
(_ Parent)-> switchTo (1);} void TestMainLayer: menuCallback2 (cocos2d: Ref * sender) {static_cast
  
   
(_ Parent)-> switchTo (2);} bool TestLayer1: init () {bool bRet = false; do {CC_BREAK_IF (! LayerColor: initWithColor (Color4B (100,200,200,100); auto winSize = Director: getInstance ()-> getWinSize (); auto label1 = Label: createWithBMFont ("bitmapFontTest3.fnt ", "MainLayer"); auto item1 = MenuItemLabel: create (label1, CC_CALLBACK_1 (TestLayer1: menuCallback1, this); auto menu = Menu: create (item1, NULL ); menu-> alignItemsVertically (); menu-> setPosition (winSize/2); addChild (menu); bRet = true;} while (0); return bRet;} void TestLayer1 :: menuCallback1 (cocos2d: Ref * sender) {// return method static_cast
   
    
(_ Parent)-> switchTo (0);} bool TestLayer2: init () {bool bRet = false; do {CC_BREAK_IF (! LayerColor: initWithColor (Color4B (100,100,200,100); auto winSize = Director: getInstance ()-> getWinSize (); auto label1 = Label: createWithBMFont ("bitmapFontTest3.fnt ", "MainLayer"); auto item1 = MenuItemLabel: create (label1, CC_CALLBACK_1 (TestLayer2: menuCallback1, this); auto menu = Menu: create (item1, NULL ); menu-> alignItemsVertically (); menu-> setPosition (winSize/2); addChild (menu); bRet = true;} while (0); return bRet;} void TestLayer2 :: menuCallback1 (cocos2d: Ref * sender) {static_cast
    
     
(_ Parent)-> switchTo (0 );}
    
   
  
 

Code download: http://download.csdn.net/detail/qqmcy/8031733

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.