Cocos2d-X 3.4版-游戏继续,游戏重新开始,回到主界面的实现《赵云要格斗》

Cocos2d-X 3.4版-游戏继续,游戏重新开始,回到主界面的实现《赵云要格斗》,第1张

概述下一节开始要用cocostudio制作主界面,为了使用最新版的Cocos Studio2.1,需要将引擎升级到3.4. 下面是3.4的升级说明。对于我们的项目来说,机会没什么影响,所以只需要用新引擎创建一个工程, 我们甚至只需要将classes,resource进行简单地覆盖就可以完成引擎升级。 更加优化的渲染流程:改进了2D和3D渲染,《Fantasy Warrior3D》现在不需要hack引擎

下一节开始要用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.0M
Cocos 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:多写博客,帮助自己,方便他人!

总结

以上是内存溢出为你收集整理的Cocos2d-X 3.4版-游戏继续,游戏重新开始,回到主界面的实现《赵云要格斗》全部内容,希望文章能够帮你解决Cocos2d-X 3.4版-游戏继续,游戏重新开始,回到主界面的实现《赵云要格斗》所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1038659.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存