0

I'm trying to erase bullets if bullets are out of window. There is a code where i want to do this:

 for (size_t i = 0; i < bullets.size();i++)
    {
        if (bullets[i]->bullet.getPosition().y < window.getPosition().y)
        {
            bullets.erase(bullets.begin()+i);
            std::cout << "USUNIETO KULE" << std::endl;
        }
        bullets[i]->bullet_draw(window);
        bullets[i]->bullet_shooting();
    }

Thanks for help.

  • After you erased `bullets[i]` you still use it to draw and shoot. This won't work very well for the last element in the vector (when `i == bullets.size() - 1`). Erase **or** draw/shoot, don't do both. – Some programmer dude Sep 13 '21 at 13:09

0 Answers0