I am trying to load 6 images into a std::vector(sf::Sprite)
into my state machine. The state machine is working fine so I doubt that it is the issue.
I have a .txt file that contains the images' file names as
1.png
2.png
3.png
4.png
5.png
6.png
The images themselves are in the img/
directory.
Here is the relevant code:
std::ifstream file("images.txt");
while (!(file.eof()))
{
getline(file, TmpString);
filename.push_back(TmpString);
}
TmpString
is just a string variable to store a single image's file name. filename
is a vector of strings and using breakpoints, I can see that it has the correct strings (aka correct file names).
In the next loop, I use loadFromFile()
to load the image into a sf::Texture
called tempTex
. I set the texture of a sf::Sprite
called tempSprite
and add it to spriteList
which is the std::vector<sf::Sprite>
.
for (size_t i = 0; i < filename.size(); i++)
{
tempTex.loadFromFile("img/" + filename[i]);
tempSprite.setTexture(tempTex, true);
spriteList.push_back(tempSprite);
}
The issue is, that whenever I draw any sprite from the spriteList to the window, its always the 6.png
image. That is:
m_window.draw(spriteList[index])
always draws 6.png
no matter what the index is.