刚开始接触这个东西,弄了好久都没有弄好,我自己太笨了,现在我将如何创建一个CCLayerMultiplex过程写出来,代码如下:
CCLayer *mainLayer = new MenuDemo;
CCLayer *menu1 = new MenuDemoItem1;
CCLayer *menu2 = new MenuDemoItem2;
CCLayer *menu3 = new MenuDemoItem3;
CCLayerMultiplex *Menu_multiplex = CCLayerMultiplex::create(mainLayer, menu1, menu2, menu3, NULL);
addChild(Menu_multiplex, 0);
mainLayer->release();
menu1->release();
menu2->release();
menu3->release();
CCDirector::sharedDirector()->replaceScene(this);
首先在你的scene中创建这个 CCLayerMultiplex,不要调换了代码顺序哦!
然后写回调函数了:
void MenuDemo::fontMenu1_callBack(CCObject *object) {
((CCLayerMultiplex*)(m_pParent))->switchTo(2);
}
void MenuDemo::fontMenu2_callBack(CCObject *object) {
((CCLayerMultiplex*)(m_pParent))->switchTo(3);
}
void MenuDemo::fontMenu3_callBack(CCObject *object) {
((CCLayerMultiplex*)(m_pParent))->switchTo(1);
}
这个MenuDemo就是当前的scene,特别要注意回调函数里面的m_pParent参数, /** A weak reference to the parent */它是之指的当前的所激活的node!
这样基本上就创建完成了!
标签:cocos2dx,CCLayer,CCLayerMultiplex,pParent,release,new,MenuDemo From: https://blog.51cto.com/u_13566975/7230890