您好,登錄后才能下訂單哦!
#ifndef __ControlButton_H__ #define __ControlButton_H__ #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; //用于標識當前按鈕的狀態 typedef enum{ touch_begin, touch_down, touch_up, }tagForTouch; class ControlButton :public CCNode { public: ControlButton(); ~ControlButton(); CREATE_FUNC(ControlButton); //創建按鈕,其中name_png為按鈕的背景圖片,button_title為按鈕圖片上要顯示的文字,num為文字的透明度0-100,0為透明 void CreateButton(const char* name_png,const char* button_title="0",unsigned int num=0); //綁寫按鈕事件 void BindButtonEven(); /* 當鼠標處于按下并曾經點中按鈕時,則觸發一次 */ void touchDownAction(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標進入按鈕范圍,則觸發一次 */ void touchDragEnter(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標離開按鈕范圍,則觸發一次 */ void touchDragExit(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標進入按鈕范圍,則觸發,只要達到條件,就不斷觸發 */ void touchDragInside(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標離開按鈕范圍,則觸發,只要達到條件,就不斷觸發 */ void touchDragOutside(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標松開且在按鈕范圍內,則觸發一次 */ void touchUpInside(Ref* pSender, Control::EventType event); /* 當鼠標處于按下并曾經點中按鈕的狀態下,鼠標松開且在按鈕范圍外,則觸發一次 */ void touchUpOutside(Ref* pSender, Control::EventType event); /* 暫時沒有發現能用鼠標觸發這個事件的操作,看了注釋,應該是由其它事件中斷按鈕事件而觸發的 */ void touchCancel(Ref* pSender, Control::EventType event); //是否按下按鈕 bool isTouch; private: //按鈕控件變量 ControlButton* controlBtn; }; #endif event 枚舉 如下: /** Kinds of possible events for the control objects. */ enum class EventType { TOUCH_DOWN = 1 << 0, // A touch-down event in the control. DRAG_INSIDE = 1 << 1, // An event where a finger is dragged inside the bounds of the control. DRAG_OUTSIDE = 1 << 2, // An event where a finger is dragged just outside the bounds of the control. DRAG_ENTER = 1 << 3, // An event where a finger is dragged into the bounds of the control. DRAG_EXIT = 1 << 4, // An event where a finger is dragged from within a control to outside its bounds. TOUCH_UP_INSIDE = 1 << 5, // A touch-up event in the control where the finger is inside the bounds of the control. TOUCH_UP_OUTSIDE = 1 << 6, // A touch-up event in the control where the finger is outside the bounds of the control. TOUCH_CANCEL = 1 << 7, // A system event canceling the current touches for the control. VALUE_CHANGED = 1 << 8 // A touch dragging or otherwise manipulating a control, causing it to emit a series of different values. };
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。