Blame view

ios/Runner/Wowgame/Classes/game_food/TwoStateButton.h 1.3 KB
cb213901   xiaoyu   添加一个游戏的源码和编译选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  //
  //  TwoStateButton.h
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 25.06.2017.
  //
  //
  
  #ifndef TwoStateButton_h
  #define TwoStateButton_h
  
  #include "SimpleButton.h"
  
  class TwoStateButton : public SimpleButton
  {
      public:
          static TwoStateButton* create(const std::string& inactiveImagePath, const std::string& activeImagePath);
          bool init(const std::string& inactiveImagePath, const std::string& activeImagePath);
  //        virtual void onEnter() override;
      
          bool isActive() {
              return _active;
          };
          void setActive(bool active);
      
          void setOnStateChangedCallback(std::function<void(bool state)> onStateChangedCallback){
              _onStateChangedCallback = onStateChangedCallback;
          };
      
          bool switchStates(){
              _active = !_active;
              return _active;
          };
      
          void addChild(cocos2d::Node* child) override;
      
      protected:
          bool _active;
          std::function<void(bool state)> _onStateChangedCallback;
          std::string _inactiveBgImagePath;
          std::string _activeBgImagePath;
          cocos2d::Sprite* _activeSprite;
          cocos2d::Sprite* _inactiveSprite;
      
          void configureTouchListeners() override;
          void adjustTextures();
  };
  
  #endif /* TwoStateButton_h */