I am trying to hold a vector of projectiles which then i would loop at the end to draw it. I tried doing so but my game immediately freeze for a second the moment i try to add a projectile in into the vector! I finally realized that its
vector.push_back() that is the one causing the weak game performance. I have tried using
deque,
list but none of them shown any improvement in performance.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { // under while (window.isOpen()) {}
if (player.canShoot) {
player.shot();//timer related, not causing any issues
fireball.setStartPos(player.getPos());
fireball.start();//start animation, not causing issues
if (pList.size() == 3) { //max 3 projectiles, pList is the vector
pList.pop_front();
}
pList.push_back(fireball); //this causing issues
}
}
Please help!