cocos3.x 扫雷08 选关界面

前端之家收集整理的这篇文章主要介绍了cocos3.x 扫雷08 选关界面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

扫雷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);
@H_923_502@ 49: }
 50:
 51: void SelectGame::MenuExitCallBack(Ref *)
 52: {
 53:     Director::getInstance()->end();
 54: }
 55:

效果如图

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

@L_301_5@

原文链接:https://www.f2er.com/cocos2dx/346015.html

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