So I've been making a 2D grid and pathfinder using SFML. Now I ran into a problem. I've been making a vector for the path nodes.
struct Node { std::pair <int, int> node; // position of the node <x,y> std::pair <int, int> previous; bool iswall = false; sf::Vector2f rectCenter = sf::Vector2f(0, 0); sf::Vector2f position; }; class Gridspot { Node start; Node end; std::vector <Node> Openset std::vector <Node> Closedset; std::vector <Node> Path; }; I then make a function so I can set grid cell's center:
void Gridspot::calculaterectCenter(sf::Vector2f& center, int i, int j) { for (auto path : Path) { if (path.node == std::make_pair(i, j)) path.rectCenter = center; break; } } in the main:
for (auto path : cell.Path) { if (i == path.node.first && j == path.node.second) { sf::Vector2f center(box[i][j].getPosition().x + box[i][j].getSize().x / 2, box[i][j].getPosition().y + box[i][j].getSize().y / 2); box[i][j].setFillColor(sf::Color::Magenta); cell.calculaterectCenter(center, i, j); } } the problem that I'm facing is that when I enter the value the vector element in question rectcenter variable doesn't change.