How to extend touch area

I would like to extend PageViewTouch area so that the touch is detected outside the current page.
I have clipping disabled and I can see multiple pages at the time. How to enable touch on non current pages?

Okay I got it and:

  1. You have to create something of the size you want touches to be detected (I just used Layout)
  2. You have to pass touch events from the layout to the widget you want to detect touches EXCEPT in onTouchBegan (there you should pass event to Layout) since it is bool function which checks if the touch was inside widget (and we want it to be detected inside layout not widget)

So it should look like this ("this" is my class derived from Layout):

        this->setPosition(widgetPosition);
	this->setSize(desiredSize);
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [this](Touch* touch, Event* eventt)
	{
		return this->Layout::onTouchBegan(touch, eventt);
	};
	listener->onTouchMoved = [this](Touch* touch, Event* eventt)
	{
		if (pageview)
		{
			pageview->onTouchMoved(touch, eventt);
		}
	};
	listener->onTouchCancelled = [this](Touch* touch, Event* eventt)
	{
		if (pageview)
		{
			pageview->onTouchCancelled(touch, eventt);
		}
	};
	listener->onTouchEnded = [this](Touch* touch, Event* eventt)
	{
		if (pageview)
		{
			pageview->onTouchEnded(touch, eventt);
		}
	};
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
2 Likes

Ah ok, I thought there was already an in-built method to set a custom touch area. I think I’ll just subclass Button and override virtual bool hitTest(const cocos2d::Vec2 &pt) so that I can set a custom Rect area for touch. Seems to work well.