//20秒后自动运行下一个场景
runAction( CCSequence::create(CCDelayTime::create(20.0f),
CCCallFunc::create(this, callfunc_selector(GameOver::removeThis)),NULL));
void GameOver::removeThis()
{
nextCallback(this);
}

.h文件

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "Box2D/Box2D.h" #include "SimpleAudioEngine.h" class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::CCScene* scene(); void menuCloseCallback(CCObject* pSender);
void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender);
void backCallback(CCObject* pSender);
void Test();
CREATE_FUNC(HelloWorld);
};
class Test1 : public HelloWorld
{
public:
Test1();
};
class Test2 : public HelloWorld
{
public:
Test2();
};
class Test3 : public HelloWorld
{
public:
Test3();
};
#endif // __HELLOWORLD_SCENE_H__

.cpp文件

#include "HelloWorldScene.h"

using namespace cocos2d;

CCLayer* nextSpriteTestAction();
CCLayer* backSpriteTestAction();
CCLayer* restartSpriteTestAction();
static int sceneIdx = -1;
typedef CCLayer* (*NEWDRAWPRIMITIVESFUNC)();
#define DRAWPRIMITIVES_CREATE_FUNC(className) \
static CCLayer* create##className() \
{ return new className(); } DRAWPRIMITIVES_CREATE_FUNC(Test1);
DRAWPRIMITIVES_CREATE_FUNC(Test2);
DRAWPRIMITIVES_CREATE_FUNC(Test3);
static NEWDRAWPRIMITIVESFUNC createFunctions[] =
{
createTest1,
createTest2,
createTest3,
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
static CCLayer* nextAction()
{
sceneIdx++;
sceneIdx = sceneIdx % MAX_LAYER;
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer->autorelease();
return pLayer;
}
static CCLayer* backAction()
{
sceneIdx--;
int total = MAX_LAYER;
if( sceneIdx < 0 )
sceneIdx += total;
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer->autorelease();
return pLayer;
}
static CCLayer* restartAction()
{
CCLayer* pLayer = (createFunctions[sceneIdx])();
pLayer->autorelease();
return pLayer;
}
void HelloWorld::restartCallback(cocos2d::CCObject *pSender)
{
if (sceneIdx != -1)
{
CCScene *s = new CCScene;
s->addChild(restartAction());
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
}
void HelloWorld::nextCallback(cocos2d::CCObject *pSender)
{
CCScene *s = new CCScene;
s->addChild(nextAction());
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void HelloWorld::backCallback(cocos2d::CCObject *pSender)
{
CCScene *s = new CCScene;
s->addChild(backAction());
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
}
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene); // 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer); // add layer as a child to scene
scene->addChild(layer);
} while (0); // return the scene
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init()); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* l = CCLabelTTF::create("Test3333333", "Thonburi", 16);
addChild(l);
l->setPosition( ccp(s.width/2,s.height/2-100));
Test(); bRet = true;
} while (0); return bRet;
}
void HelloWorld::Test()
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemImage *item1 = CCMenuItemImage::create("b1.png", "b2.png", this, menu_selector(HelloWorld::backCallback));
CCMenuItemImage *item2 = CCMenuItemImage::create("r1.png", "r2.png", this, menu_selector(HelloWorld::restartCallback));
CCMenuItemImage *item3 = CCMenuItemImage::create("f1.png", "f2.png", this, menu_selector(HelloWorld::nextCallback));
CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,menu_selector(HelloWorld::menuCloseCallback));
CCMenu *menu = CCMenu::create(item1, item2, item3,pCloseItem, NULL);
menu->setPosition(CCPointZero);
item1->setPosition(ccp(s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2));
item2->setPosition(ccp(s.width/2, item2->getContentSize().height/2));
item3->setPosition(ccp(s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2));
pCloseItem->setPosition(ccp(s.width - 20, s.height-20));
addChild(menu, 100);
}
Test1::Test1()
{
Test();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* l = CCLabelTTF::create("Test1", "Thonburi", 16);
addChild(l);
l->setPosition( ccp(s.width/2,s.height/2));
}
Test2::Test2()
{
Test();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* l = CCLabelTTF::create("Test2", "Thonburi", 16);
addChild(l);
l->setPosition( ccp(s.width/2,s.height/2));
}
Test3::Test3()
{
Test();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* l = CCLabelTTF::create("Test3", "Thonburi", 16);
addChild(l);
l->setPosition( ccp(s.width/2,s.height/2));
}

cocos2d-x——在一个cpp中展示多个场景的更多相关文章

  1. MFC 如何在一个类中使用在其他类中定义的变量或函数

    [声明:本文的知识点来源于网络,参考网址:https://blog.csdn.net/bill_ming/article/details/7407848] [以下三种方法亲测有效,可以根据具体情况来选 ...

  2. SharePoint Iframe 报错“此内容不能显示在一个框架中”<续>

    在之前的SharePoint站点iframe引用中,我们遇到过下面的问题,就是其它系统或者不通环境的SharePoint站点,引用SharePoint页面会报错“此内容不能显示在一个框架中”,之前我们 ...

  3. 为什么super()和this()调用语句不能同时在一个构造函数中出现的解释

    我想这应该是Java构造函数的一种机制吧,首先以子类和父类为例.当你创建一个子类的实例时,首先会调用父类的构造函数,然后再调用子类的构造函数,如果父类中没有缺省构造函数,则必须再子类的构造函数中显示的 ...

  4. python使用matplotlib在一个图形中绘制多个子图以及一个子图中绘制多条动态折线问题

    在讲解绘制多个子图之前先简单了解一下使用matplotlib绘制一个图,导入绘图所需库matplotlib并创建一个等间隔的列表x,将[0,2*pi]等分为50等份,绘制函数sin(x).当没有给定x ...

  5. SQL语句 在一个表中插入新字段

    SQL语句 在一个表中插入新字段: alter table 表名 add 字段名 字段类型 例: alter table OpenCourses add Audio varchar(50)alter ...

  6. template 不能分别在.h和.cpp中定义模板

    先上代码: #ifndef SEQLIST_H #define SEQLIST_H #include <iostream> ; template <typename type> ...

  7. 【编程题目】在一个字符串中找到第一个只出现一次的字符。如输入 abaccdeff,则输出 b。

    第 17 题(字符串):题目:在一个字符串中找到第一个只出现一次的字符.如输入 abaccdeff,则输出 b. 思路:此题非常容易. 最开始是想开辟一块空间存储每个字符出现的次数. 但转念一想,似乎 ...

  8. MVC中在一个视图中,怎么加载另外一个视图?

    在RazorView.cshtml视图: <!--在视图中调用无返回值的方法,视图中调用无返回值的方法,要加上大括号--> <!--在一个视图中,直接加载另外一个视图--> @ ...

  9. SharePoint Iframe 报错“此内容不能显示在一个框架中”

    问题描述 我们SharePoint站点用Excel Service发布的Excel,需要Iframe到其他系统中,但是,Iframe的时候发现报错“此内容不能显示在一个框架中”. 后来,尝试在其他系统 ...

随机推荐

  1. Django学习系列之Form基础

     Django学习系列之Form基础 2015-05-15 07:14:57 标签:form django 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追 ...

  2. ramips芯片,openwrt安装njit8021xclient

    1.软件安装包 http://pan.baidu.com/s/1tcY2p 解压并通过winscp上传至路由器,利用putty进入控制台,依次输入以下4条命令,每次输入后点一次执行opkg insta ...

  3. 第二百八十九天 how can I 坚持

    今天好伤啊,太把自己当回事了. 现在在弟弟这,下午和他一块看了看西客站附近的房子,感觉暂时好难,只是暂时的,一切都会好起来的. 弟弟上班也挺不容易,不该来给他添麻烦,替他心疼. 确实不知道该咋办了,好 ...

  4. 【转】深受开发者喜爱的10大Core Data工具和开源库

    http://www.cocoachina.com/ios/20150902/13304.html 在iOS和OSX应用程序中存储和查询数据,Core Data是一个很好的选择.它不仅可以减少内存使用 ...

  5. POJ 2421 Constructing Roads (最小生成树)

    Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D Description There ar ...

  6. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  7. UINavigationController切换controller动画设置

    http://blog.csdn.net/dabiaoyanjun/article/details/7774775 uinavigationcontrolleranimation在pushViewCo ...

  8. 虚拟攻防系统 HoneyPot

    转载原地址 http://www.2cto.com/Article/200410/9.html Honeypot 是一个故意设计为有缺陷的系统,通常是用来对入侵者的行为进行警报或者 诱骗.传统的 Ho ...

  9. SOURCES的文件格式

    SOURCES的文件格式: TARGETNAME=drivername , -本参数用于指定生成的设备驱动程序名称(不需后缀名),所产生的文件 -为drivername.sys. TARGETPATH ...

  10. WinDbg x 64 使用 SOS: 无法找到运行时 DLL (clr.dll)

     http://www.datazx.cn/Forums/en-US/59aa78c9-dc05-43c8-9efe-e7b132056afc/action?threadDisplayName=win ...