Hey !
I want to draw a few Sprites which are located in the same folder (assets/playerIcon/NUMBER.png).
I don't understand why my code isn't working. On my app I can only see the last sprite and the others are just replaced by a white square.
Could someone help me ? Thank you in advance !
static vector<Sprite> playerIcon;
static vector<Texture> playerIconVectorTexture;
int playerIconNumber = 4;
for (int i = 0; i < playerIconNumber; i++) {
std::string fileLocation = "assets/playerIcon/";
fileLocation += std::to_string(i) + ".png";
std::cout << fileLocation << std::endl;
Texture playerIconTexture;
Sprite playerIconSprite;
if (!playerIconTexture.loadFromFile(fileLocation))
{
writeToLog("Error");
exit(0);
}
else {
playerIconTexture.setSmooth(true);
playerIconVectorTexture.insert(playerIconVectorTexture.begin(), playerIconTexture);
playerIconSprite.setTexture(playerIconVectorTexture.front());
playerIconSprite.setPosition(Vector2f(200+(i*100), 400));
playerIcon.push_back(playerIconSprite);
}
}
And later :
for (Sprite x : playerIcon) {
window.draw(x);
}