hello,I need to listen to touch events on a sprite node and then try to swallow touch move events followed by the touch event.
I need something like this:
sprite.onTouch(callback);// calls the call back on sprite touch
or
Events.listen(sprite,TouchStart,callback);
Events.unlisten(sprite,TouchStart,callback);
auto sprite = Sprite::create(“file.png”);
…
auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
listener~~>setSwallowTouch;
listener~~>onTouchBegan = [](Touch* touch, Event* event) { do_some_thing(); return true; };
listener~~>onTouchMoved = { do_some_thing; };
listener~~>onTouchCancelled = [](Touch* touch, Event* event) { do_some_thing(); };
// The priority of the touch listener is based on the draw order of sprite
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, sprite);
// Or the priority of the touch listener is a fixed value
EventDispatcher::getInstance()->addEventListenerWithFixedPriority(listener, 100); // 100 is a fixed value