What’s the proper way of doing this? I have letter buttons inside ‘_letterTilesPool’ Vector. so when i press those buttons , I want to execute someFunctions() … but I cant place a function inside. it generates error
in GameScene.cpp:
auto listener1 = EventListenerTouchOneByOne::create();
listener1->setSwallowTouches(true);
for(auto pic: _letterTilesPool){ //attach TOUCHEVENT to all sprite inside my vector
listener1->onTouchBegan = [pic](Touch* touch, Event* event){
auto target = static_cast<CCTiles*>(event->getCurrentTarget());
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
//log("you pressed letter %c", target->getLetterVal());
checkForMatches(); // <---------- ERROR
target->setOpacity(180); // works fine,
return true;
}
return false;
};
ERROR says:
‘this’ cannot be implictly captured in this context.
What’s the proper way of doing this?