您好,登錄后才能下訂單哦!
#ifndef __ControlButton_H__ #define __ControlButton_H__ #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; //用于標(biāo)識(shí)當(dāng)前按鈕的狀態(tài) typedef enum{ touch_begin, touch_down, touch_up, }tagForTouch; class ControlButton :public CCNode { public: ControlButton(); ~ControlButton(); CREATE_FUNC(ControlButton); //創(chuàng)建按鈕,其中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(); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕時(shí),則觸發(fā)一次 */ void touchDownAction(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)進(jìn)入按鈕范圍,則觸發(fā)一次 */ void touchDragEnter(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)離開按鈕范圍,則觸發(fā)一次 */ void touchDragExit(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)進(jìn)入按鈕范圍,則觸發(fā),只要達(dá)到條件,就不斷觸發(fā) */ void touchDragInside(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)離開按鈕范圍,則觸發(fā),只要達(dá)到條件,就不斷觸發(fā) */ void touchDragOutside(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)松開且在按鈕范圍內(nèi),則觸發(fā)一次 */ void touchUpInside(Ref* pSender, Control::EventType event); /* 當(dāng)鼠標(biāo)處于按下并曾經(jīng)點(diǎn)中按鈕的狀態(tài)下,鼠標(biāo)松開且在按鈕范圍外,則觸發(fā)一次 */ void touchUpOutside(Ref* pSender, Control::EventType event); /* 暫時(shí)沒有發(fā)現(xiàn)能用鼠標(biāo)觸發(fā)這個(gè)事件的操作,看了注釋,應(yīng)該是由其它事件中斷按鈕事件而觸發(fā)的 */ 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. };
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。