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方法

  • 相关阅读:
    解决png图像透明问题
    常用的CSS命名规则
    站点跨域登录
    SVN服务器配置
    开源方便的PHP & Flash图表:Open Flash Chart
    php+mysql无限级分类(非递归)
    地址栏显示图标 Shortcut Icon
    mysql set类型和enum类型
    通过 WebDAV 协议访问版本库(http://)
    年薪第一的数据库工程师是怎样炼成的
  • 原文地址:https://www.cnblogs.com/Colored-Mr/p/4240233.html
Copyright © 2011-2022 走看看