Hello I've been having a problem with using a vector of sf::Sprites/sf::Images:
std::vector<sf::Image> IMAGE;
std::vector<sf::Sprite> SPRITE;
IMAGE.push_back(sf::Image());
SPRITE.push_back(sf::Sprite());
IMAGE.at(0).LoadFromFile("Remilia0.png");
SPRITE.at(0).SetImage(IMAGE.at(0));
IMAGE.push_back(sf::Image());
SPRITE.push_back(sf::Sprite());
IMAGE.at(1).LoadFromFile("Remilia1.png");
SPRITE.at(1).SetImage(IMAGE.at(1));
IMAGE.push_back(sf::Image());
SPRITE.push_back(sf::Sprite());
IMAGE.at(2).LoadFromFile("Remilia2.png");
SPRITE.at(2).SetImage(IMAGE.at(2));
IMAGE.push_back(sf::Image());
SPRITE.push_back(sf::Sprite());
IMAGE.at(3).LoadFromFile("Remilia3.png");
SPRITE.at(3).SetImage(IMAGE.at(3));
IMAGE.push_back(sf::Image());
SPRITE.push_back(sf::Sprite());
IMAGE.at(4).LoadFromFile("Remilia4.png");
SPRITE.at(4).SetImage(IMAGE.at(4));
SPRITE.at(0).SetPosition(20, 20);
SPRITE.at(1).SetPosition(60, 20);
SPRITE.at(2).SetPosition(100, 20);
SPRITE.at(3).SetPosition(140, 20);
SPRITE.at(4).SetPosition(180, 20);
while(Window.IsOpened())
{
Window.GetEvent(Event);
if(Event.Type == sf::Event::Closed)Window.Close();
Window.Clear();
Window.Draw(SPRITE.at(0));
Window.Draw(SPRITE.at(1));
Window.Draw(SPRITE.at(2));
Window.Draw(SPRITE.at(3));
Window.Draw(SPRITE.at(4));
Window.Display();
}
It seems as though when I push a new Sprite (or Image) into their vectors all of the other objects get erased because every sprite shows up as a white square except for the last sprite to be pushed into the vector (SPRITE.at(4) draws fine).
Can someone explain why this is happening?
BTW: I'm using SFML 1.6 in VS08