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

效果如图

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

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...