I have a vector containing values of a custom class and I’m trying to capture it by reference in a touchListener but none of the values inside of the vector are getting captured.
vector<Player> players;
//add some stuff to players
CCLOG("%i", players.size()); //logs 4
auto touchListener = EventListenerTouchAllAtOnce::create();
touchListener->onTouchesBegan = [&](const std::vector<Touch*> &touches, Event* event) {
for(int i = 0; i < touches.size(); ++i){
auto p = touches[i]->getLocation();
CCLOG("%i", players.size()); //logs 0 when it should log 4
for (Player j : players) {
//do some stuff
}
}
}
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
Any help would be greatly appreciated