加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos3.x 扫雷08 选关界面

发布时间:2020-12-14 19:32:15 所属栏目:百科 来源:网络整理
导读:扫雷 08 选关界面 选关界面使用 cocos studio 来制作 新建一个文件 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:

扫雷08 选关界面

选关界面使用cocos studio来制作

新建一个文件

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"
 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,monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: white"> 23:
 24:     auto hardItem = static_cast<ui::Button*>(rootNode->getChildByName("Bhard"));
 25:     hardItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuHardCallBack,monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: #f4f4f4"> 26:
 27:     auto exitItem = static_cast<ui::Button*>(rootNode->getChildByName("Bexit"));
 28:     exitItem->addTouchEventListener(CC_CALLBACK_1(SelectGame::MenuExitCallBack,monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: white"> 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:

效果如图

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读