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. KO工作原理及带来的好处

    介绍 Knockout是一个以数据模型(data model)为基础的能够帮助你创建富文本,响应显示和编辑用户界面的JavaScript类库.任何时候如果你的UI需要自动更新(比如:更新依赖于用户的行 ...

  2. opencv获取像素的值

    opencv中获取图像像素的方法 方法一: IplImage *img = cvLoadImage("Lena.jpg", 0); CvScalar pixel; for (int ...

  3. CF 1003B Binary String Constructing 【构造/找规律/分类讨论】

    You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b ...

  4. CF 1005A Tanya and Stairways 【STL】

    Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...

  5. HDU 2473 Junk-Mail Filter 【并查集删除】

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. Dijkstra算法解决单源最短路径

    单源最短路径问题:给定一个带权有向图 G = (V, E), 其中每条边的权是一个实数.另外,还给定 V 中的一个顶点,称为源.现在要计算从源到其他所有各顶点的最短路径长度.这里的长度是指路上各边权之 ...

  7. 【动态规划】UVALive - 4888 - Railroad

    f(i,j)表示从A序列前面取i个,从B序列前面取j个时,能否拼成C序列.转移自行脑补. A train yard is a complex series of railroad tracks for ...

  8. 【贪心】bzoj3709 [PA2014]Bohater

    把怪分成两类看: 一.回血>损血 则若先杀损血少的再杀损血多的,则为当前这一步提供了更高的可能性.因为血量是单增的,所以尽量用较少的血量去干♂耗血较少的怪物. 二.回血<损血 则若先杀回血 ...

  9. @requestBody注解的使用(上)

    1.@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,比如说:application/json或者是ap ...

  10. JavaScript异步编程的Promise模式(转)

    异步模式在web编程中变得越来越重要,对于web主流语言Javascript来说,这种模式实现起来不是很利索,为此,许多Javascript库(比如 jQuery和Dojo)添加了一种称为promis ...