Okay, these code do not work:
void Weapon::Draw(RenderWindow &window, Map &m)
{
iterator = 0;
for (i=begin(pociski);i!=end(pociski);)
{
pocisk = *i;
pocisk.move(Velocity[iterator]);
pociski[iterator] = pocisk;
for (vector<Sprite>::iterator j = m.walls.begin(); j < m.walls.end(); j++)
{
Sprite sciana = *j;
if (areColliding(pocisk, sciana, 2))
{
i = pociski.erase(i);
}
}
window.draw(*i);
iterator++;
}
}
for (;i!=pociski.end();)
{
pocisk = *i;
pocisk.move(Velocity[iterator]);
pociski[iterator] = pocisk;
for (vector<Sprite>::iterator j = m.walls.begin(); j < m.walls.end(); j++)
{
Sprite sciana = *j;
if (areColliding(pocisk, sciana, 2))
{
i = pociski.erase(i);
}
else
{
++i;
}
}
window.draw(*i);
iterator++;
}
for (i=pociski.begin();i!=pociski.end();)
{
pocisk = *i;
pocisk.move(Velocity[iterator]);
pociski[iterator] = pocisk;
for (vector<Sprite>::iterator j = m.walls.begin(); j < m.walls.end(); j++)
{
Sprite sciana = *j;
if (areColliding(pocisk, sciana, 2))
{
vector<Sprite>::iterator curr = i++;
pociski.erase(curr);
}
else
{
++i;
}
}
window.draw(*i);
iterator++;
}
for (auto i = pociski.begin(); i != pociski.end();)
{
pocisk = *i;
pocisk.move(Velocity[iterator]);
pociski[iterator] = pocisk;
for (vector<Sprite>::iterator j = m.walls.begin(); j < m.walls.end(); j++)
{
Sprite sciana = *j;
if (areColliding(pocisk, sciana, 2))
{
i = pociski.erase(i);
}
else
{
i++;
}
}
window.draw(*i);
iterator++;
}
It's answers by googe when type "c++ erase vector iterator in loop" Any dont work. Any other sugestions? ;/