Hi. I have multiple sprites in a scene. I’m trying to set up touch listeners. It partially works. The problem is only 1 sprite is being registered. It’s like it’s covering the entire screen and blocking the other sprites from being touched. The sprites were created in cocos studio. The are 8 toolboxes spread out on the screen. Any help would be appreciated.
//set up touch listeners
auto listener = cocos2d::EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [](Touch* touch, Event* event){
Vec2 loc = touch->getLocation();
CCLOG(“x:%f,y:%f”,loc.x,loc.y);
CCLOG("%s",event->getCurrentTarget()->getName().c_str());
return true;
};
for(auto node:toolBoxes){
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener->clone(), node);
}