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

前端之家收集整理的这篇文章主要介绍了Cocos2d-X 3.4版-游戏继续,游戏重新开始,回到主界面的实现《赵云要格斗》前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下一节开始要用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

  1. //
  2. // GamepauseScene.h
  3. // Fight
  4. //
  5. // Created by Cytzrs on 15/2/5.
  6. //
  7. //
  8.  
  9. #ifndef __Fight__GamepauseScene__
  10. #define __Fight__GamepauseScene__
  11.  
  12. #include <iostream>
  13. #include "cocos2d.h"
  14. #include "cocos-ext.h"
  15. USING_NS_CC_EXT;
  16. USING_NS_CC;
  17. class GamepauseScene : public Layer
  18. {
  19. public:
  20. static Scene* createScene(RenderTexture*);
  21. bool init();
  22. CREATE_FUNC(GamepauseScene);
  23. void attackAct1(Ref *sender,Control::EventType controlEvent);
  24. void attackAct2(Ref *sender,Control::EventType controlEvent);
  25. void attackAct3(Ref *sender,Control::EventType controlEvent);
  26. //private:
  27. // ControlButton* attackBtn1;
  28. // ControlButton* attackBtn2;
  29. // ControlButton* attackBtn3;
  30. };
  31.  
  32. #endif /* defined(__Fight__GamepauseScene__) */

GamepauseScene.cpp

  1. //
  2. // GamepauseScene.cpp
  3. // Fight
  4. //
  5. // Created by Cytzrs on 15/2/5.
  6. //
  7. //
  8.  
  9. #include "GamepauseScene.h"
  10. #include "cocos-ext.h"
  11. USING_NS_CC_EXT;
  12. #include "HelloWorldScene.h"
  13. Scene* GamepauseScene::createScene(RenderTexture* render)
  14. {
  15. auto scene = Scene::create();
  16. auto layer = GamepauseScene::create();
  17. scene->addChild(layer,1);
  18. auto s = Director::getInstance()->getVisibleSize();
  19. auto bg = Sprite::createWithTexture(render->getSprite()->getTexture());
  20. bg->setPosition(s/2);
  21. bg->setFlippedY(true);
  22. bg->setColor(cocos2d::Color3B::GRAY);
  23. scene->addChild(bg);
  24.  
  25. return scene;
  26. }
  27.  
  28. bool GamepauseScene::init()
  29. {
  30. while(1)
  31. {
  32. if(!Layer::init())
  33. return false;
  34. auto s = Director::getInstance()->getVisibleSize();
  35. ControlButton* attackBtn1 = ControlButton::create("继续游戏","fonts/Marker Felt.ttf",30);
  36. attackBtn1->setPosition(s/2);
  37. this->addChild(attackBtn1,7);
  38. attackBtn1->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct1),Control::EventType::TOUCH_DOWN);
  39. ControlButton* attackBtn2 = ControlButton::create("重新游戏",30);
  40. attackBtn2->setPosition(s.width/2,s.height/2-100);
  41. this->addChild(attackBtn2,7);
  42. attackBtn2->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct2),Control::EventType::TOUCH_DOWN);
  43. ControlButton* attackBtn3 = ControlButton::create("回到主界面",30);
  44. attackBtn3->setPosition(s.width/2,s.height/2-200);
  45. this->addChild(attackBtn3,7);
  46. attackBtn3->addTargetWithActionForControlEvents(this,cccontrol_selector(GamepauseScene::attackAct3),Control::EventType::TOUCH_DOWN);
  47. //
  48. // attackBtn2 = ControlButton::create("ATTACK",30);
  49. // attackBtn2->setPosition(Vec2(visibleSize.width-200,100));
  50. // this->addChild(attackBtn2,7);
  51. //
  52. // attackBtn3 = ControlButton::create("ATTACK",30);
  53. // attackBtn3->setPosition(Vec2(visibleSize.width-200,100));
  54. // this->addChild(attackBtn3,7);
  55. return true;
  56. }
  57. return false;
  58. }
  59.  
  60. void GamepauseScene::attackAct1(Ref *sender,Control::EventType controlEvent)
  61. {
  62. // auto scene = HelloWorld::createScene();
  63. Director::getInstance()->popScene();
  64. }
  65.  
  66. void GamepauseScene::attackAct2(Ref *sender,Control::EventType controlEvent)
  67. {
  68. auto scene = HelloWorld::createScene();
  69. Director::getInstance()->replaceScene(scene);
  70. }
  71.  
  72. void GamepauseScene::attackAct3(Ref *sender,Control::EventType controlEvent)
  73. {
  74. // auto scene = HelloWorld::createScene();
  75. //现在还没有创建主界面,暂且留白
  76. Director::getInstance()->popScene();
  77. }

工程源码

PS:多写博客,帮助自己,方便他人!

猜你在找的Cocos2d-x相关文章