//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. redis的string类型

    string : string类型是二进制安全的, 可以包含任何数据,比如jpg图片或者序列化的对象 . 方法 : set : 设置key对应的值为string类型的value set  name   ...

  2. openstack 云平台API

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAKrCAIAAACV8EEMAAAgAElEQVR4nOydeVgUaZ7n/W9299nd7n

  3. 转】Maven学习总结(六)——Maven与Eclipse整合

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/4052025.html 感谢! 一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E ...

  4. Hibernate之管理session与批处理

    1. Hibernate 自身提供了三种管理Session对象的方法 –Session对象的生命周期与本地线程绑定 –Session 对象的生命周期与JTA事务绑定 –Hibernate 委托程序管理 ...

  5. 问题-Delphi2007编译时提示内存错误“sxs.dll. No Debug Info.ACCESS 0xXXXXX"

    相关资料:http://bbs.csdn.net/topics/340132341 问题现象:在调试程序时,未进工程文件中的TApplication.Run;证明不是代码问题. 问题原因:可能是因为* ...

  6. [iOS UI进阶 - 5.0] 手势解锁Demo

    A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件   code source: https://github.com/hellovoidworld/GestureUnlockDemo     B ...

  7. Android子线程更新UI的方法总结

    版权声明:本文为博主原创文章,转载请注明出处:https://i.cnblogs.com/EditPosts.aspx?postid=6121280 消息机制,对于Android开发者来说,应该是非常 ...

  8. list对象排序

    在数据库中查出来的列表list中,往往需要对不同的字段重新排序,一般的做法都是使用排序的字段,重新到数据库中查询.如果不到数据库查询,直接在第一次查出来的list中排序,无疑会提高系统的性能. 只要把 ...

  9. struts validate

    1  login.jsp方式1 <%@ page language="java" import="java.util.*" pageEncoding=&q ...

  10. cocos2d-x CCScrollView

    转自:http://www.cnblogs.com/dcxing/archive/2012/12/31/2840217.html ScrollView一般用在游戏的关卡选择这种类似的场景还有帮助这种场 ...