下一节开始要用cocostudio制作主界面,为了使用最新版的Cocos Studio2.1,需要将引擎升级到3.4.
下面是3.4的升级说明。对于我们的项目来说,机会没什么影响,所以只需要用新引擎创建一个工程,
我们甚至只需要将classes,resource进行简单地覆盖就可以完成引擎升级。
更加优化的渲染流程:改进了2D和3D渲染,《Fantasy Warrior3D》现在不需要hack引擎就可以运行
更小的包体积:iOS和Android平台上,使用系统网络库替换了第三方库libcurl,iOS的游戏包大小从5.6M缩小到4.3M,Android的APK游戏包大小从2.9M缩小到2.0MCocos Package Manager: 引擎扩展模块化框架,使得基于Cocos2d-x的扩展,更方便地集成与发布,现在GAF已经应用到这个框架中
视锥体裁剪功能:通过计算裁剪掉在屏幕上不可见物体,降低渲染开销,为4.0的全3D和大规模场景提供支持
在这一节里,我从Evakaka大神的博客里学到不少东西,以前我做遮罩从来没用过这样的
方式,现在想起来,真是既简单有粗暴,实在惭愧。
总的来说,这以功能实现起来,在原理上还是非常显而易见的,只不过在具体的实现上,还
是要见仁见智。
主要来说,我们需要新建一个Scene,当我们按下暂定按钮时,见我们新建的这个Scene push出来,
,之所以不用replaceScene是因为,我们总不能一按暂定按钮回来的时候游戏就重新开始吧。
GamepauseScene.h
// // GamepauseScene.h // Fight // // Created by Cytzrs on 15/2/5. // // #ifndef __Fight__GamepauseScene__ #define __Fight__GamepauseScene__ #include <iostream> #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC_EXT; USING_NS_CC; class GamepauseScene : public Layer { public: static Scene* createScene(RenderTexture*); bool init(); CREATE_FUNC(GamepauseScene); void attackAct1(Ref *sender,Control::EventType controlEvent); void attackAct2(Ref *sender,Control::EventType controlEvent); void attackAct3(Ref *sender,Control::EventType controlEvent); //private: // ControlButton* attackBtn1; // ControlButton* attackBtn2; // ControlButton* attackBtn3; }; #endif /* defined(__Fight__GamepauseScene__) */
GamepauseScene.cpp
// // GamepauseScene.cpp // Fight // // Created by Cytzrs on 15/2/5. // // #include "GamepauseScene.h" #include "cocos-ext.h" USING_NS_CC_EXT; #include "HelloWorldScene.h" Scene* GamepauseScene::createScene(RenderTexture* render) { auto scene = Scene::create(); auto layer = GamepauseScene::create(); scene->addChild(layer,1); auto s = Director::getInstance()->getVisibleSize(); auto bg = Sprite::createWithTexture(render->getSprite()->getTexture()); bg->setPosition(s/2); bg->setFlippedY(true); bg->setColor(cocos2d::Color3B::GRAY); scene->addChild(bg); return scene; } bool GamepauseScene::init() { while(1) { if(!Layer::init()) return false; auto s = Director::getInstance()->getVisibleSize(); ControlButton* attackBtn1 = ControlButton::create("继续游戏","fonts/Marker Felt.ttf",30); attackBtn1->setPosition(s/2); this->addChild(attackBtn1,7); attackBtn1->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct1),Control::EventType::TOUCH_DOWN); ControlButton* attackBtn2 = ControlButton::create("重新游戏",30); attackBtn2->setPosition(s.width/2,s.height/2-100); this->addChild(attackBtn2,7); attackBtn2->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct2),Control::EventType::TOUCH_DOWN); ControlButton* attackBtn3 = ControlButton::create("回到主界面",30); attackBtn3->setPosition(s.width/2,s.height/2-200); this->addChild(attackBtn3,7); attackBtn3->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct3),Control::EventType::TOUCH_DOWN); // // attackBtn2 = ControlButton::create("ATTACK",30); // attackBtn2->setPosition(Vec2(visibleSize.width-200,100)); // this->addChild(attackBtn2,7); // // attackBtn3 = ControlButton::create("ATTACK",30); // attackBtn3->setPosition(Vec2(visibleSize.width-200,100)); // this->addChild(attackBtn3,7); return true; } return false; } void GamepauseScene::attackAct1(Ref *sender,Control::EventType controlEvent) { // auto scene = HelloWorld::createScene(); Director::getInstance()->popScene(); } void GamepauseScene::attackAct2(Ref *sender,Control::EventType controlEvent) { auto scene = HelloWorld::createScene(); Director::getInstance()->replaceScene(scene); } void GamepauseScene::attackAct3(Ref *sender,Control::EventType controlEvent) { // auto scene = HelloWorld::createScene(); //现在还没有创建主界面,暂且留白 Director::getInstance()->popScene(); }
工程源码
PS:多写博客,帮助自己,方便他人!
原文链接:/cocos2dx/344499.html