I made a vector, vectorOfEnemies and vectorOfBullets witch I want to destroy the object when they intersect on the map(sry for the bad english).
for (int i = 0; i < enemy1.vectorOfEnemies.size(); i++) {
for (int j = 0; j < bullet1.vectorOfBullets.size(); j++) {
if (enemy1.vectorOfEnemies[i].getGlobalBounds().intersects(bullet1.vectorOfBullets[j].getGlobalBounds())) {
/*enemy1.vectorOfEnemies.erase(enemy1.vectorOfEnemies.begin() + i);
for (int k = i; k < enemy1.vectorOfEnemies.size() - 1; k++) {
enemy1.vectorOfEnemies[k] = enemy1.vectorOfEnemies[k + 1];
} enemy1.vectorOfEnemies.pop_back();
bullet1.vectorOfBullets.erase(bullet1.vectorOfBullets.begin() + i);
for (int l = i; l < bullet1.vectorOfBullets.size() - 1; l++) {
bullet1.vectorOfBullets[l] = bullet1.vectorOfBullets[l + 1];
} bullet1.vectorOfBullets.pop_back();
for (int p = i; p < bullet1.vectorOfRotations.size(); p++) {
bullet1.vectorOfRotations[p] = bullet1.vectorOfRotations[p + 1];
} bullet1.vectorOfRotations.pop_back();*/
bullet1.cateGloante++;
//std::cout << bullet1.cateGloante;
game.clear();
game.display();
}
}
}
that is the code I tried to do to destroy the objects and when I run the program when the objects intersect the program crashes with the error "Expression: vecot subscript out of range"