ControlButton 事件
#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.
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.