Just for some background information, I am developing in SFML on Mac OS 10.5 in XCode, and the image I am trying to display is a .png
In my Scene class I have a vector<sf::Sprite> which contains all the sprites for that scene. I have populated the array with one sprite:
sf::Image img1;
img1.LoadFromFile("images/psnail.png");
sf::Sprite spr1;
spr1.SetImage(img1);
spr1.SetPosition(200, 200);
spriteArray->push_back(spr1);
Now, in my main game loop, I ask the scene for its list of sprites, iterating through and drawing them:
app.Clear();
// Draw scene's sprites
std::vector<sf::Sprite>* spriteArray = mainScene->getSprites();
for (int i=0; i<spriteArray->size(); i++)
{
app.Draw(spriteArray->at(i));
}
app.Display();
This draws a sprite in the correct location and size: (200,200) and 32x32, however it is only a white box. What I dont understand is that if I reset the sprites image in the draw loop right before drawing it, it works; ie:
for (int i=0; i<spriteArray->size(); i++)
{
sf::Image img1;
img1.LoadFromFile("images/psnail.png");
spriteArray->at(i).SetImage(img1);
app.Draw(spriteArray->at(i));
}
This draws the sprite correctly. Anybody have any idea whats going on? The code is exactly the same in both places--why would the sprite show up as a white block if I set its image before inserting it into the array?[/code]