cocos2dx 3.x(Button傳統按鈕)


 1 //
 2 //  ATTLoagingScene.hpp
 3 //  ATT
 4 //
 5 //  Created by work on 16/10/13.
 6 //
 7 //
 8 
 9 #ifndef ATTLoagingScene_hpp
10 #define ATTLoagingScene_hpp
11 
12 #include <stdio.h>
13 #include "cocos2d.h"
14 #include "cocos-ext.h"//使用按鈕事件,必須要需要的頭文件
15 USING_NS_CC_EXT;//使用按鈕事件,必須要需要的命名空間
16 
17 class ATTLoagingScene : public cocos2d::Layer
18 
19 {
20 
21    
22 private:
23 
24     cocos2d::ui::Button * m_soundOnButton;//私有的成員變量
25 
26     cocos2d::ui::Button * m_btnPlus;
27 
28       
29 
30 public:
31 
32     static cocos2d::Scene* createScene();    
33 
34     virtual bool init();
35 
36 //聲明點擊事件
37 
38     void menuCloseCallback(Ref *ref,cocos2d::extension::Control::EventType event);//對原來的關閉事件進行改造,增加參數,讓其支持cccontrol_selector
39 
40     // implement the "static create()" method manually
41 
42     CREATE_FUNC(ATTLoagingScene);
43 
44 };
45 
46  
47 
48 #endif /* ATTLoagingScene_hpp */

 

 

 1 //
 2 //  ATTLoagingScene.cpp
 3 //  ATT
 4 //
 5 //  Created by work on 16/10/13.
 6 //
 7 //
 8 
 9 #include "ATTLoagingScene.hpp"
10 #include "SimpleAudioEngine.h"
11 #include "ATTGameScene.hpp"
12 USING_NS_CC;
13 
14 Scene* ATTLoagingScene::createScene()
15 {
16     // 'scene' is an autorelease object
17     auto scene = Scene::create();
18     
19     // 'layer' is an autorelease object
20     auto layer = ATTLoagingScene::create();
21     
22     // add layer as a child to scene
23     scene->addChild(layer);
24     
25     // return the scene
26     return scene;
27 }
28 
29 
30 bool ATTLoagingScene::init()
31 {
32     
33     
34     if ( !Layer::init() )
35     {
36         return false;
37     }
38 
39 
40 auto soundbg=cocos2d::ui::Scale9Sprite::createWithSpriteFrameName("gobang_option_sound_off.png");
41     soundbg->setScale(0.667);
42     m_soundOnButton=ControlButton::create(soundbg);
43     m_soundOnButton->setPreferredSize(cocos2d::Size(162,58));
44     m_soundOnButton->setPosition(getPoint(1136, 627));
45     m_soundOnButton->addTargetWithActionForControlEvents(this, cccontrol_selector(GoBangScene::buttonSoundOnCallBack), Control::EventType::TOUCH_UP_INSIDE);
46     this->addChild(m_soundOnButton,2);
47     m_soundOnButton->setVisible(false);//設置為隱藏,true為可見。
48     m_soundOnButton->setEnabled(false);//設置為禁用,true為可用。
49     m_soundOnButton->setOpacity(200);//透明度 setOpacity 透明度 0~255(取值范圍),255不透明,0全透明 
50 
61    
62 
63 //
64 
65     return true;
66 }
67 
68 // 實現點擊方法
69 #pragma mark - ATTGameScene::optionCB(設置按鈕)
70 void ATTGameScene::buttonSoundOnCallBack(Ref *pSender, cocos2d::ui::Widget::TouchEventType type)
71 {
72     /* 
73      *判斷當前點擊類型(只響應一次,松開時生效)
74      */
75     if (type != cocos2d::ui::Widget::TouchEventType::ENDED)
76     {
77         return;
78     }
79     // 直接取反 (判斷當前節點是否被隱藏,若隱藏直接取反)
80     //m_optionNode->setVisible(!m_optionNode->isVisible());
81 
82 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM