Hello, i have a function which send by reference, textures and sprites to vectors. First time i made this function i had a problem. Generally speaking by tapping "i", sprites that are inside my vector of sprites should be displayed. What i get is first sprite (usually) displayed correctly and rest of them (again... usually) are white squares. After that by tapping "i" again sprites are cleared, and than again displayed by pressing the same button. But after that second time, they are displaying correctly. Below is fragment of my code:
vector<Items*> YourItems = hero->openBackpack();
sf::Texture tempTItems;
sf::Sprite tempSItems;
for (int i = 0; i < YourItems.size(); i++)
{
if (!(THeroItems.size() == YourItems.size()))
{
THeroItems.push_back(tempTItems);
SHeroItems.push_back(tempSItems);
}
YourItems[i]->getLook(THeroItems[i], SHeroItems[i]);
}
Then i remake this function. I've come up (a little randomly) with something like that:
if (!(THeroItems.size() == YourItems.size()))
{
int tempSize = THeroItems.size();
for (int i = 0; i < YourItems.size() - tempSize; i++)
{
THeroItems.push_back(tempTItems);
SHeroItems.push_back(tempSItems);
}
}
for (int i = 0; i < YourItems.size(); i++)
{
YourItems[i]->getLook(THeroItems[i], SHeroItems[i]);
}
And... that works... After some debugging i found out that pushing back vector is changing elements of sprite vector. Because of that sprites are pointing some rubbish things. And i don't have any clue why. I will be very gratefull for help. I'm not sure if amount of code provided is enaugh. If not, than i will paste more. Please help!