I have a PointManager class which inserts Points (another class) into an std::list. Point insertion works just fine.
However, these "Points" contain, among other things, an x and y value which are often changing.
I'd like to be able to tell my PointManger to UpdateAll(), and have it iterate through the std::list, and set the position of each Point's sprite(sf::Sprite, from SFML) to that point's most recent x and y values.
As it is, I know that each point's Update() method is being called successfully from PointManager's UpdateAll(), but none of the changes taking place in Point::Update() are reflected in PointManager. If I print PointManager's contents, no x and y values have changed and the sprites on screen haven't moved.
Any help will be met with eternal gratefulness and possibly sandwiches. I have been stuck on this for a solid 2 days now, and nothing I can think to google has solved my problem. Thank you in advance!
That code looks okay. Though it could be shortened to itr->Update();.
The problem could be with how you manage _x and _y values. Try changing your cout to _id << " updating from " << Sprite.getPosition().x << ", " << Sprite.getPosition().y << " to " << _x << ", " << _y << '\n';.
Interesting. The problem must be somewhere else. Right now it's just outputting:
Point 1 updating from 0,0 to 0,0
Point 2 updating from 13,12 to 13,12
etc.
So no changes are being made. It may have to do with how I'm manipulating _x and _y, though I imagine my SetX() function in the Point class is fine... -_-
I will have to think about this some more. Thank you for verifying that this snippet of code should be working, though!
EDIT: FIXED IT! My problem was, after all, the method by which I was manipulating the Points. I was trying to explicitly change their values from my main() method, where I should have implemented a method in PointManager that iterates through, finds the right point, and changes _x and _y by itself. If that makes any sense. In any case, thank you again.