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. docker容器间通信

    现在在我们的docker中已经有了三个容器,分别是DB/API/UI三个容器,三个容器间肯定是要进行互相通信的 可以查看docker的官方文档,https://docs.docker.com/engi ...

  2. mysql 文本搜索

    全文本搜索 MySQL支持几种基本的数据库引擎,但并非所有的引擎都支持全文本搜索.两个最常使用的引擎为MyISAM和InnoDB,前者支持全文本搜索,后者就不支持. 理解全文本搜索 在前面的学习中,我 ...

  3. Codeforces 651 C. Watchmen-曼哈顿距离和欧几里得距离

    C. Watchmen   time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  4. codeforces Round #441 C Classroom Watch【枚举/注意起点】

    C. time limit per test 1 second memory limit per test 512 megabytes input standard input output stan ...

  5. 使用 Hibernate 完成 HibernateUtils 类 (适用于单独使用Hibernate或Struts+Hibernate)

    package com.istc.Utilities; import org.hibernate.Session; import org.hibernate.SessionFactory; impor ...

  6. ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  7. ( 转 ) mysql复合索引、普通索引总结

    对于复合索引:Mysql从左到右的使用索引中的字段,一个查询可以只使用索引中的一部份,但只能是最左侧部分.例如索引是key index (a,b,c). 可以支持a | a,b| a,b,c 3种组合 ...

  8. SSH框架的简单含义

    典型的J2EE三层结构,分为表现层.中间层(业务逻辑层)和数据服务层.三层体系将业务规则.数据访问及合法性校验等工作放在中间层处理.客户端不直接与数据库交互,而是通过组件与中间层建立连接,再由中间层与 ...

  9. 【费用流】BZOJ1061[NOI2008]-志愿者招募

    [题目大意] 一个项目需要n天完成,其中第i天至少需要Ai个人.共有m类人可以招募,其中第i类可以从第Si天做到第Ti天,每人的招募费用为Ci元.求最小招募费用. [思路] byvoid神犇的建图详解 ...

  10. 解决VM虚拟机中的ubuntu不能全屏的问题

    Ctrl+alt+T:打开终端 输入命令:sudo apt install open-vm* 运行之后重启一下虚拟机就可以了