cocos3.x 扫雷08 选关界面

扫雷08 选关界面

 

选关界面使用cocos studio来制作

 

cocos3.x 扫雷08 选关界面_第1张图片

cocos3.x 扫雷08 选关界面_第2张图片

新建一个文件

cocos3.x 扫雷08 选关界面_第3张图片

cocos3.x 扫雷08 选关界面_第4张图片

cocos3.x 扫雷08 选关界面_第5张图片

SelectGame.h头文件

   1: #ifndef __SELECT_GAME_H__
   2: #define __SELECT_GAME_H__
   3: #include "customer_define.h"
   4:  
   5:  
   6: class SelectGame :public LayerColor
   7: {
   8: public:
   9:     CREATE_FUNC(SelectGame);
  10:     SCENE_FUNC(SelectGame);
  11:     bool init();
  12:     //回调函数
  13: protected:
  14:     void MenuEasyCallBack(Ref*);
  15:     void MenuMidCallBack(Ref*);
  16:     void MenuHardCallBack(Ref*);
  17:     void MenuExitCallBack(Ref*);
  18: };
  19:  
  20: #endif // !__SELECT_GAME_H__

SelectGame.Cpp文件

   1: #include "SelectGame.h"
   2: #include "GameScene.h"
   3: #include "cocostudio/CocoStudio.h"
   4: #include "ui/CocosGUI.h"
   5:  
   6: using namespace cocostudio::timeline;
   7:  
   8: bool SelectGame::init()
   9: {
  10:     if (!LayerColor::initWithColor(Color4B(64 , 76 , 128 , 255))) {
  11:         return false;
  12:     }
  13:     
  14:     //从csb文件中获取图层
  15:     auto rootNode = CSLoader::createNode("select.csb");
  16:     addChild(rootNode);
  17:     //获取按钮,关联回调函数
  18:     auto easyItem = static_cast<ui::Button*>(rootNode->getChildByName("Beasy"));
  19:     easyItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuEasyCallBack , this));
  20:  
  21:     auto midItem = static_cast<ui::Button*>(rootNode->getChildByName("Bmid"));
  22:     midItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuMidCallBack , this));
  23:  
  24:     auto hardItem = static_cast<ui::Button*>(rootNode->getChildByName("Bhard"));
  25:     hardItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuHardCallBack , this));
  26:  
  27:     auto exitItem = static_cast<ui::Button*>(rootNode->getChildByName("Bexit"));
  28:     exitItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuExitCallBack , this));
  29:     return true;
  30: }
  31:  
  32: void SelectGame::MenuEasyCallBack(Ref *)
  33: {
  34:     Scene * scene = GameScene::scene(1);
  35:     Director::getInstance()->replaceScene(scene);
  36:  
  37: }
  38:  
  39: void SelectGame::MenuMidCallBack(Ref *)
  40: {
  41:     Scene * scene = GameScene::scene(2);
  42:     Director::getInstance()->replaceScene(scene);
  43: }
  44:  
  45: void SelectGame::MenuHardCallBack(Ref *)
  46: {
  47:     Scene * scene = GameScene::scene(3);
  48:     Director::getInstance()->replaceScene(scene);
  49: }
  50:  
  51: void SelectGame::MenuExitCallBack(Ref *)
  52: {
  53:     Director::getInstance()->end();
  54: }
  55:  

效果如图

本次效果不是很好,按钮点击切换的图片看不出来。背景由于透明的的影响,也是不怎么好看的。

cocos3.x 扫雷08 选关界面_第6张图片

你可能感兴趣的:(cocos3.x 扫雷08 选关界面)