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