温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ControlButton 事件

发布时间:2020-08-05 22:35:34 来源:网络 阅读:356 作者:libinqi456 栏目:开发技术
#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.
    };
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI