cocos2d-x-3.0rc1 学习笔记4(场景切换2)
2014-04-12 10:18
435 查看
前面的的别人写的,研究了一下有点懂了,然后自己仿造HelloWorld 写了一个,模板的是在AppDelegate中调用 scene ,我就在菜单按钮的回调函数里调用
.h 中
cpp 中
.h 中
class Newscene : public cocos2d::Layer { 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 recommend returning the class instance pointer static cocos2d::Scene* scene(); // a selector callback void menuCloseCallback(Ref* sender); void menuCloseCallback1(Ref* sender); // implement the "static node()" method manually CREATE_FUNC(Newscene); };
cpp 中
Scene* Newscene::scene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object Newscene *layer = Newscene::create(); // add layer as a child to scene scene->addChild(layer); return scene; } bool Newscene::init() { if ( !Layer::init() ) { return false; } auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); //添加一个标题层 auto cocoa=LabelTTF::create("HelpTxt", "Arial", TITLE_FONT_SIZE*2); cocoa->setPosition(Point(visibleSize.width/2,visibleSize.height/2+cocoa->getContentSize().height)); this->addChild(cocoa,1); //背景精灵 LayerColor* clo=LayerColor::create(Color4B(0,255,255,100),visibleSize.width,visibleSize.height); this->addChild(clo); //添加2个菜单按钮 auto closeIt=MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(Newscene::menuCloseCallback,this)); auto closeIt1=MenuItemLabel::create(LabelTTF::create("Back", "Arial", TITLE_FONT_SIZE)); closeIt1->setCallback(CC_CALLBACK_1(Newscene::menuCloseCallback1,this)); auto menuu=Menu::create(closeIt,closeIt1,NULL); closeIt->setPosition(Point(visibleSize.width/2-30,visibleSize.height/2+20)); menuu->setPosition(Point(visibleSize.width/2,100)); this->addChild(menuu,1); return true; } //退出help void Newscene::menuCloseCallback(Ref* sender) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); return; #endif Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif } //返回原先场景 help void Newscene::menuCloseCallback1(Ref* sender) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); return; #endif auto sc=HelloWorld::scene(); Director::sharedDirector()->replaceScene(TransitionRotoZoom::create(1.0,sc)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif } //调用一个新的场景 void HelloWorld::menuCloseCallback2(Ref* sender) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); return; #endif auto sc=Scene::create(); Newscene* la=Newscene::create(); sc->addChild(la); Director::sharedDirector()->replaceScene(CCTransitionFadeTR::create(1.0,sc)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif }
相关文章推荐
- cocos2d-x-3.0rc1 学习笔记3(场景切换)
- 【Cocos2d-x 3.0学习笔记】场景切换
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第二十课:Cocos2D-X场景切换1-3
- Cocos2d-x学习笔记(四)-------->场景切换
- IOS cocos2d学习笔记-<七>CCTransitionScene场景切换动画
- cocos2d-x学习笔记4 场景的切换
- Cocos2d-x学习笔记(五)实例——场景切换
- Cocos2d-x学习笔记(九)实例——场景自动切换
- cocos2d-x 菜鸟学习笔记四(游戏场景与场景切换)
- Cocos2D-X学习笔记 3 从一个场景切换到还有一个场景
- cocos2d-x学习笔记(3)场景切换
- Cocos2d-x学习笔记(八)场景切换原理分析
- cocos2d-x学习笔记(5)-- CCScene场景的切换
- cocos2d-x学习笔记(二)--场景切换
- cocos2d-x学习笔记04:CCScene场景切换
- cocos2d学习笔记第一章 基础场景创建及基本配置
- cocos2d-x 2.0.4 学习笔记(一)场景、层、精灵
- 【Cocos2d-html5游戏引擎学习笔记(7)】CCLayer创建及场景跳转
- 阿J的cocos2d-x学习笔记-元素消消看(二)-主场景的创建
- cocos2d-html5学习笔记(五)--菜单和场景转换