Hi... So, I have a std::list of enemies spawning on the screen. I have included sf::Text in the condition where the enemies are erased from the list to show the score whenever an enemy is erased. I did the int to string conversion. It works. The score is shown as 1 for the first enemy killed. But for every consecutive enemy, it is not being incremented. What might be the mistake? Please tell me!
std::list<sf::Sprite>::iterator enemyit = enemy.begin(), next;
int erased = 0;
long double score = 0;
std::string str;
while(enemyit != enemy.end())
{
next = enemyit;
next++;
if(enemyit->getGlobalBounds().intersects(player.getGlobalBounds()))
{
enemy.erase(enemyit);
++erased;
++score;
str = std::to_string(score);
text.setString(str);
}
enemyit = next;
}
window.draw(text);