Notification node does not swallow touches

Hi there, is notification node capable of swallowing touches on running scene?

Just create a blank Layer that swallows touches and you can place it anywhere, anytime.

Ex:
BlockTapsLayer.h

#include <stdio.h>
#include "cocos2d.h"

USING_NS_CC;

class BlockTapsLayer: public Layer {
public:
    BlockTapsLayer();
    ~BlockTapsLayer();
    
    CREATE_FUNC(BlockTapsLayer);
    virtual void setup();
};

BlockTapsLayer.cpp

#include "BlockTapsLayer.hpp"

BlockTapsLayer::BlockTapsLayer() { }
BlockTapsLayer::~BlockTapsLayer() { }

void BlockTapsLayer::setup() {
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [&](Touch* touch, Event* event) {
        return true;
    };
    
    listener->onTouchEnded = [&](Touch* touch, Event* event) {
        this->onTouchEnded(touch, event);
    };
    
    auto dispatcher = this->getEventDispatcher();
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}

Now just BlockTapsLayer::create() and make sure the z order is correct where you place it, then add/remove anywhere.

Sorry if this doesn’t directly answer the question, but sometimes creating something you can reuse generically will solve more than one problem.

Not as far as I know, but it would be trivial to try.

However, as @tdebock mentioned there are more full-proof/more flexible ways of handing what you would want to do.

I did have that kind of layer with ui::Layout as a child of Notification node. A weird situation is when I disable Touches of ui::Layout, all its children are not touchable. When Notification node popups, touches will always touch through Notification node toward running scene.

I knew adding a layer to running scene will solve this problem, but I’m curious about the usage of Notification node.

Why did you need a layout specifically? I find that for me it is easiest to just layout using my own logic so I have complete flexibility.

Actially I’m using RelativeBox for positioning all my childrens. ui::Layout touches work as I excepted when adding to running scene, but not Notification Node. I have a bunch of scene transition between, and Popup’s on Notification Node will not fadeout during scenes transition. Originally I had designed with one scene for entire game, using actions to do fadeout for transition between layout. But if user interact rapidly during this kind of transition will fadeout both layout. Such as a button on A transition from A to B and a button on B return from B to A. If Notification node is not capable of intercepting touches above running scene I might go for BlockTapsLayer solution.