cocos3.x 扫雷08 选关界面

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

扫雷08 选关界面

选关界面使用cocos studio来制作

新建一个文件

SelectGame.h文件

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

SelectGame.Cpp文件

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

效果如图

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

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