zoukankan      html  css  js  c++  java
  • cocos2d-x:解决点击拖动按钮后,所在的layer监听不到触摸事件的问题

    点击拖动按钮后,想让所在的layer监听到屏幕的触摸事件,可以把该按钮拖动开始的时候设置setTouchEnabled为false;
    例:

    #include "ui/UIButton.h"
    
    bool myDemo::init() {
    
      
    
      // 设置点击事件
      EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create();
      listener->onTouchBegan = CC_CALLBACK_2( myDemo::onTouchBegan, this );
      listener->onTouchMoved = CC_CALLBACK_2( myDemo::onTouchMoved, this );
      listener->onTouchEnded = CC_CALLBACK_2( myDemo::onTouchEnded, this );
    
    
      // 绑定
      getEventDispatcher()->addEventListenerWithSceneGraphPriority( listener, this );
    
      
    
      // 按钮创建
      Button *btn = ***;      
      btn ->addTouchEventListener( CC_CALLBACK_2( myDemo::BtnCallBack, this ) );
    
      this->addChild( btn  );
      return true;
    }
    
    void myDemo::BtnCallBack( Ref *p, cocos2d::ui::Widget::TouchEventType type ) {
    
      Button *btn = (Button *)p; // 
    
      if ( type == Widget::TouchEventType::BEGAN ) {
        btn->setTouchEnabled( false );
    
      }
    
    }
    
     
    
    bool myDemo::onTouchBegan( cocos2d::Touch *touch, cocos2d::Event *event ) {
    
      return true;
    
    }
    
     
    
    void myDemo::onTouchMoved( cocos2d::Touch *touch, cocos2d::Event *event ) {
    
    
    }
    
     
    
    void myDemo::onTouchEnded( cocos2d::Touch *touch, cocos2d::Event *event ) {
    
    
    }

    //当拖动按钮时,会进入onTouchMoved方法

  • 相关阅读:
    Django级联删除的选项
    Mysql远程连接配置
    Node.js中http-server的使用
    MySQL大小写问题
    将Mysql的一张表导出至Excel格式文件
    图像处理之直方图均衡化及C源码实现
    图像处理之双边滤波介绍与源码实现
    图像滤波之高斯滤波介绍
    图像处理之中值滤波介绍及C实现
    图像处理之均值滤波介绍及C算法实现
  • 原文地址:https://www.cnblogs.com/Colored-Mr/p/4240233.html
Copyright © 2011-2022 走看看