使用Cocos Studio 1.6 编辑开始界面

使用Cocos Studio 编辑开始界面

 

cocos Studio 图片

 

 

其中的按钮等尺寸应于图片尺寸一样

 

代码:

获取并添加界面,并实现按钮的点击功能

 

MainVie.h

 

 1 #ifndef __MAIN_SCENE_H__
 2 #define __MAIN_SCENE_H__
 3 
 4 #include "cocos2d.h"
 5 #include "cocos-ext.h"
 6 
 7 using namespace cocos2d::extension;
 8 USING_NS_CC;
 9 using namespace cocos2d::gui;
10 
11 class MainView : public UILayer
12 {
13 public:
14 
15     static CCScene* createScene();
16     bool init();
17     CREATE_FUNC(MainView);
18     void initView();
19 
20     // 音乐按钮
21     void menuMusicCallBack(CCObject* pSender, TouchEventType type);
22     // 开始按钮
23     void menuStartCallBack(CCObject* pSender, TouchEventType type);
24     // 商城按钮
25     void menuShopCallBack(CCObject* pSender, TouchEventType type);
26 
27 
28 private:
29   // 获取界面的容器
30     Widget* m_wUI;
31   // 为了获取 TextField 中的内容
32     char strName[256];
33     char strPassword[256];
34 
35     // 开始按钮
36     UIButton* m_btnStart;
37     // 音乐按钮
38     UIButton* m_btnMusic;
39     // 商城按钮
40     UIButton* m_btnShop;
41 
42     UITextField* m_pEditName;
43     UITextField* m_pEditPassword;
44 
45 };
46 
47 
48 #endif // __MAIN_SCENE_H__

 

MainVie.cpp

 

 1 #include "MainView.h"
 2 
 3 CCScene* MainView::createScene(){
 4 
 5     CCScene *scene = CCScene::create();
 6     CCLayer *layer = MainView::create();
 7     scene->addChild(layer);
 8     return scene;
 9 }
10 
11 bool MainView::init(){
12 
13     if (!UILayer::init()){
14         return false;
15     }
16 
17     initView();
18 
19     return true;
20 
21 }
22 
23 void MainView::initView(){
24 
25     // 获取cocosStudio创建的登陆界面
26     m_wUI = GUIReader::shareReader()->widgetFromJsonFile("dengluView/dengluView.ExportJson");
27     addWidget(m_wUI);
28     // 获取音乐按钮,并添加点击事件
29     m_btnMusic = dynamic_cast<UIButton*>(m_wUI->getChildByName("Button_Music"));
30     m_btnMusic->addTouchEventListener(this, toucheventselector(MainView::menuMusicCallBack));
31     // 获取商城按钮,并添加点击事件
32     m_btnShop = dynamic_cast<UIButton*>(m_wUI->getChildByName("Button_Shop"));
33     m_btnShop->addTouchEventListener(this, toucheventselector(MainView::menuShopCallBack));
34     // 获取开始按钮,并添加点击事件
35     m_btnStart = dynamic_cast<UIButton*>(m_wUI->getChildByName("Button_Play"));
36     m_btnStart->addTouchEventListener(this, toucheventselector(MainView::menuStartCallBack));
37 
38 }
39 
40 
41 // 音乐按钮
42 void MainView::menuMusicCallBack(CCObject* pSender, TouchEventType type){
43     CCLog("menuMusicCallBack");
44 }
45 // 开始按钮
46 void MainView::menuStartCallBack(CCObject* pSender, TouchEventType type){
47     CCLog("menuStartCallBack");
48 }
49 // 商城按钮
50 void MainView::menuShopCallBack(CCObject* pSender, TouchEventType type){
51     CCLog("menuShopCallBack");
52 }

 

结果图:

 

 

posted @ 2015-09-09 11:55  silent-bobo  阅读(642)  评论(0编辑  收藏  举报