有时候需要在一个界面上切换不同的Layer,这就需要用到CCLayerMultiplex来管理多层layer。
实现的效果如图:
代码很简单就不多说了:
CCLayer* pHomeLayer=HomeLayer::create();
CCLayer* pFBLayer=FBLayer::create();
pLayerMultiplex=CCLayerMultiplex::create(pHomeLayer , pFBLayer , pFBLayer , pFBLayer , pFBLayer , pFBLayer , NULL);
this->addChild(pLayerMultiplex , 1);
切换布景:
void MainScene::onMenu(CCObject* pSender)
{
CCMenuItem* item=(CCMenuItem*)pSender;
pLayerMultiplex->switchTo(item->getTag());
//和switchTo 的区别是,会先释放当前处于活动状态的图层,再让参数中要求的图层处于活动状态
pLayerMultiplex->switchToAndReleaseMe(item->getTag());
}
转载请注明出处:http://blog.csdn.net/Vestigge