LayerMultiplex是层的控制器类

使用例如以下

LayerMultiplexTest.h

//
// LayerMultiplexTest.h
// cpp4
//
// Created by 杜甲 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 杜甲 on 10/13/14.
//
// #include "LayerMultiplexTest.h" Scene* LayerMultiplexTest::scene()
{
// 'scene' is an autorelease object
auto scene = Scene::create(); // 'layer' is an autorelease object
LayerMultiplexTest *layer = LayerMultiplexTest::create(); // add layer as a child to scene
scene->addChild(layer); // return the scene
return scene;
} bool LayerMultiplexTest::init()
{
bool bRet = false;
do {
CC_BREAK_IF(!Layer::init()); auto mainLayer = TestMainLayer::create();
auto layer1 = TestLayer1::create();
auto layer2 = TestLayer2::create();
//将层放入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<LayerMultiplex *>(_parent)->switchTo(1); } void TestMainLayer::menuCallback2(cocos2d::Ref *sender)
{
static_cast<LayerMultiplex *>(_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)
{
//返回 方法
static_cast<LayerMultiplex *>(_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<LayerMultiplex *>(_parent)->switchTo(0); }

代码下载:http://download.csdn.net/detail/qqmcy/8031733

Cocos2d-x3.2 LayerMultiplex使用说明的更多相关文章

  1. cocos2d-x3.0创建第一个jsb游戏

    第一步: 最新的cocos2d-x.下载地址https://github.com/cocos2d/cocos2d-x github上最新的引擎,值得注意的是官网上发布的引擎是稳定版.选择哪种就看个人喜 ...

  2. Cocos2d坐标系转换

    Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...

  3. Cocos2d-x之LayerMultiplex的使用

    1.用处 用于管理Layer的切换,而不用切换场景. 2.代码 1).h文件 #include "cocos2d.h" #include "ui/CocosGUI.h&q ...

  4. Atitit.项目修改补丁打包工具 使用说明

    Atitit.项目修改补丁打包工具 使用说明 1.1. 打包工具已经在群里面.打包工具.bat1 1.2. 使用方法:放在项目主目录下,执行即可1 1.3. 打包工具的原理以及要打包的项目列表1 1. ...

  5. awk使用说明

    原文地址:http://www.cnblogs.com/verrion/p/awk_usage.html Awk使用说明 运维必须掌握的三剑客工具:grep(文件内容过滤器),sed(数据流处理器), ...

  6. 小尝试一下 cocos2d

    好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...

  7. 采用cocos2d-x lua 制作数字滚动效果样例

    require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...

  8. Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板

    很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...

  9. “我爱背单词”beta版发布与使用说明

    我爱背单词BETA版本发布 第二轮迭代终于画上圆满句号,我们的“我爱背单词”beta版本已经发布. Beta版本说明 项目名称 我爱背单词 版本 Beta版 团队名称 北京航空航天大学计算机学院  拒 ...

随机推荐

  1. 网络大数据分析 -- 使用 ElasticSearch + LogStash + Kibana 来可视化网络流量

    https://blog.csdn.net/yeasy/article/details/45332493

  2. webloader上传图片详细教程/使用thinkphp5.0(原创)

    这个插件对后端程序员相当友好,无论是JAVA还是PHP,抑或python,基本只需要一句代码就能完成上传并且预览的效果,先上效果图,让你们眼馋一下 废话不说,直接撸代码,前端代码如下: <htm ...

  3. [UML] 如何找参与者、找用例

    如何找参与者 1.谁会来使用这个系统? 2.谁会来安装这个系统? 3.谁会来启动这个系统? 4.谁会来维护这个系统? 5.谁会来关闭这个系统? 6.哪些系统会来使用这个系统? 7.谁会从这个系统获取信 ...

  4. 5、Django实战第5天:首页和登录页面的配置

    从这天开始我们需要用到前端源码,需要的朋友可以进行小额打赏(15元),打赏二维码在博客的右侧,打赏后可以凭截图联系463951510@qq.com,博主收到邮件后会立即回复发送所有源码素材,实战过程中 ...

  5. [BZOJ4772]显而易见的数论(数论)

    4772: 显而易见的数论 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 76  Solved: 32[Submit][Status][Discuss ...

  6. 【找规律】URAL - 2069 - Hard Rock

    题解及证明:http://www.cnblogs.com/StupidBoy/p/5241258.html #include<cstdio> #include<algorithm&g ...

  7. Scala零基础教学【81-89】

    第81讲:Scala中List的构造是的类型约束逆变.协变.下界详解 首先复习四个概念——协变.逆变.上界.下界 对于一个带类型参数的类型,比如 List[T]: 如果对A及其子类型B,满足 List ...

  8. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. MathType如何插入连乘

    这个就是连乘符号,只不过看着不习惯......就在眼皮子底下.

  10. WebApi_HelpPage

        HelpPage是描述WebApi接口信息的Web页,根据项目编译的Xml文件生成,包括接口的Router地址.请求参数.请求参数示例.响应参数.响应参数示例等,可方便调用方快速了解接口信息 ...