Cocos2d-x3.2 LayerMultiplex使用说明
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); }
Cocos2d-x3.2 LayerMultiplex使用说明的更多相关文章
- cocos2d-x3.0创建第一个jsb游戏
第一步: 最新的cocos2d-x.下载地址https://github.com/cocos2d/cocos2d-x github上最新的引擎,值得注意的是官网上发布的引擎是稳定版.选择哪种就看个人喜 ...
- Cocos2d坐标系转换
Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系(高中数学里面那种). 笛卡尔坐标系 笛卡尔坐标系中定义右手系原点在左下角,x向右,y向上,z向外,OpenGL坐标系为笛卡尔右 ...
- Cocos2d-x之LayerMultiplex的使用
1.用处 用于管理Layer的切换,而不用切换场景. 2.代码 1).h文件 #include "cocos2d.h" #include "ui/CocosGUI.h&q ...
- Atitit.项目修改补丁打包工具 使用说明
Atitit.项目修改补丁打包工具 使用说明 1.1. 打包工具已经在群里面.打包工具.bat1 1.2. 使用方法:放在项目主目录下,执行即可1 1.3. 打包工具的原理以及要打包的项目列表1 1. ...
- awk使用说明
原文地址:http://www.cnblogs.com/verrion/p/awk_usage.html Awk使用说明 运维必须掌握的三剑客工具:grep(文件内容过滤器),sed(数据流处理器), ...
- 小尝试一下 cocos2d
好奇 cocos2d 到底是怎样一个框架,正好有个项目需要一个游戏框架,所以稍微了解了一下.小结一下了解到的情况. 基本概念 首先呢,因为 cocos2d 是基于 pyglet 做的,你完全可以直接用 ...
- 采用cocos2d-x lua 制作数字滚动效果样例
require "Cocos2d"require "Cocos2dConstants"local testscene = class("testsce ...
- Cocos2d 利用继承Draw方法制作可显示三维数据(宠物三维等)的三角形显示面板
很久没有写博客了,这段时间比较忙,又是搬家又是做自己的项目,还有太多琐碎的事情缠身,好不容易抽出时间把最近自己做的一些简单例子记录一下. 在我的项目中,我需要一个显示面板来显示游戏中的一个三维数据,例 ...
- “我爱背单词”beta版发布与使用说明
我爱背单词BETA版本发布 第二轮迭代终于画上圆满句号,我们的“我爱背单词”beta版本已经发布. Beta版本说明 项目名称 我爱背单词 版本 Beta版 团队名称 北京航空航天大学计算机学院 拒 ...
随机推荐
- 运行微信支付demo
首先要说说写这篇文章的初衷:集成支付宝支付运行demo都是可以正常运行的,但是我下载下来微信支付的demo,却发现一大堆报错,而且相关文章几乎没有,可能大家觉得没必要,也许你觉得很简单:但是技术大牛都 ...
- [BZOJ1491][NOI2007]社交网络 floyd
1491: [NOI2007]社交网络 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2196 Solved: 1170[Submit][Status ...
- AC日记——曼哈顿交易 洛谷 P3730
曼哈顿交易 思路: 都是套路: 代码: #include <cmath> #include <cstdio> #include <cstring> #include ...
- python 2 控制台传参,解包,编码问题初探
python 2 控制台传参,需要从sys模块中导入argv,argv返回的第一个参数当前脚本(script)的文件名,后面是参数,参数个数必须和解包(unpack)时使用的参数个数一致 1.本例子演 ...
- spoj - Longest Common Substring(后缀自动机模板题)
Longest Common Substring 题意 求两个串的最长公共子串. 分析 第一个串建后缀自动机,第二个串在自动机上跑,对于自动机上的结点(状态)而言,它所代表的最大长度为根结点到当前结点 ...
- SHELL 在指定行的前/后插入指定内容
#如果知道行号可以用下面的方法 sed -i '88 r b.file' a.file #在a.txt的第88行插入文件b.txt awk '1;NR==88{system("cat ...
- 《ggplot2:数据分析与图形艺术》,读书笔记
第1章 简介 1.3图形的语法 第2章从qplot开始入门 1.基本用法:qplot(x,y,data) x是自变量横轴,y是因变量纵轴,data是数据框 2.图形参数 colour=I(&quo ...
- nodeJs建立简单的服务器
var http = require('http');//http依赖 var hostname = '127.0.0.1';//本地 var port = 3000;//端口 var server ...
- nullptr 与 constexpr
nullptr nullptr出现的目的自然是替换NULL的低位.C++可能会将NULL.0视为同一种东西.这取决于编译器是如何定义的,有的编译器定义NULL为 ( (void * )0) ,有的 ...
- 电脑(台式机||笔记本)开机password忘记通用解决方法
方法:直接制作一个老毛桃装机版u盘启动盘 网址:老毛桃官网 步骤:依照网址的解说,将制作好的U盘插入到电脑的usb插口.执行Windows 登入password破解菜单,搜索password所在的盘符 ...