2017-07-20 5 views
0

私はいくつかのボタンがあるレイヤー(ベースレイヤー)を持っています。時には半透明レイヤー上にモーダルダイアログボックスを表示したいと思います。半透明レイヤーの下のものをクリックすることはできません。基本レイヤーのボタンをクリックすることはできません。タッチを吸収したり接触したりする透明なレイヤーを作成するにはどうすればよいですか?

どのようにこれらのタッチをすべて吸収するようにレイヤーを取得するには?今、半透明レイヤのどこかをクリックして、下のレイヤーにボタンがあると、ボタンがクリックされますか?設定する必要があるフラグがありますか?

答えて

2

レイヤーにタッチリスナーを追加できます。

void YourLayerYouWantToSwallowTouches::addEvents() { 

    auto listener = cocos2d::EventListenerTouchOneByOne::create(); 
    listener->setSwallowTouches(true); 

    listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event) { 

     if (this->getBoundingBox().containsPoint(touch->getLocation())) { 

      //touchBegan(touch); // You can call touchBegan() for that layer here 
      return true; // to indicate that we have consumed touch. 
     } 
     return false; // we did not consume touch, pass thru. 
    }; 

    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); 
} 
関連する問題