vs2012 cocos2dx中CCControlButton绑定点击事件无回调

环境:window7 vs2012 cocos2d-x-2.2.6
代码:
void ControlButton::CreateButton(const char* name_png,const char* button_title,unsigned int num)
{
    //得到按钮图片的大小
    CCScale9Sprite* btn = CCScale9Sprite::create(name_png);
    CCLOG("%f",btn->getContentSize().width);
    CCLOG("%f",btn->getContentSize().height);
    int  png_height=static_cast<int>(btn->getContentSize().height);
    int  png_width=static_cast<int>( btn->getContentSize().width);
    btn->release();

    //要显示的图片大小
    CCRect rect = CCRectMake(0,0,png_width,png_height);   //图片的大小
    CCRect rectInsets = CCRectMake(1,1,1,1); //left,right,width,height

    //按钮标题,Marker Felt为字体类型,png_height为字体高度
    CCLabelTTF *title = CCLabelTTF::create("", "Marker Felt",png_height-10);
    //title->setOpacity(num);//设置可见度
    //正常状态下的按钮图片
    CCScale9Sprite *btnNormal = CCScale9Sprite::create(name_png,rect,rectInsets);

    //创建按钮
    controlBtn = CCControlButton::create(title,btnNormal);
 //绑定事件
//controlBtn->setBright(true);
controlBtn->setEnabled(true);
controlBtn->setTouchEnabled(true);
BindButtonEven();
    this->addChild(controlBtn);
}
void ControlButton::BindButtonEven()
{
     if(!this->controlBtn)
        return;
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchDownAction),CCControlEventTouchDown);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchDragEnter),CCControlEventTouchDragEnter);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchDragExit),CCControlEventTouchDragExit);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchDragInside),CCControlEventTouchDragInside);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchDragOutside),CCControlEventTouchDragOutside);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchUpInside),CCControlEventTouchUpInside);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchUpOutside),CCControlEventTouchUpOutside);
    this->controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlButton::touchCancel),CCControlEventTouchCancel);

}
/* 当鼠标处于按下并曾经点中按钮时,则触发一次 */
void ControlButton::touchDownAction(CCObject* pSender, CCControlEvent event)
{
    isTouch=true;
}
/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标进入按钮范围,则触发一次 */
void ControlButton::touchDragEnter(CCObject* pSender, CCControlEvent event)
{

}
/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标离开按钮范围,则触发一次 */
void ControlButton::touchDragExit(CCObject* pSender, CCControlEvent event)
{

}
/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标进入按钮范围,则触发,只要达到条件,就不断触发 */
void ControlButton::touchDragInside(CCObject* pSender, CCControlEvent event)
{

}
/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标离开按钮范围,则触发,只要达到条件,就不断触发 */
void ControlButton::touchDragOutside(CCObject* pSender, CCControlEvent event)
{

}
/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围内,则触发一次 */
void ControlButton::touchUpInside(CCObject* pSender, CCControlEvent event)
{
    isTouch=false;

}

/* 当鼠标处于按下并曾经点中按钮的状态下,鼠标松开且在按钮范围外,则触发一次 */
void ControlButton::touchUpOutside(CCObject* pSender, CCControlEvent event)
{

}
/* 暂时没有发现能用鼠标触发这个事件的操作,看了注释,应该是由其它事件中断按钮事件而触发的 */
void ControlButton::touchCancel(CCObject* pSender, CCControlEvent event)
{

}

执行
btn=ControlButton::create();
btn->CreateButton("bt.png");
btn->setPosition(ccp(100,100));
this->addChild(btn,2);

发现点击的时候,没有回调 touchDownAction 这些事件,求大神帮忙看一下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值