I am creating a simple game using QT c ++, I have an asteroid class and a Qvector of said class. Every 15 seconds an asteroid is created and added to the Qvector.
void MainWindow::generarAsteroides(){
srand(time(NULL));
int aleatorio=1+rand()%1000;
int a_w = 30+rand()%200;
v_asteroides.push_back(new asteroides(aleatorio,-1000,a_w,a_w,500));
mundo->addItem(v_asteroides.last());
std::cout << "Asteroide generado en X : "<< aleatorio << std::endl;
sonido->stop();
sonido->setMedia(QUrl("qrc:/multimedia/suspenso1.mp3"));
sonido->play();
}
when it exceeds a certain Y coordinate, I call a function through a Timer to traverse the vector and eliminate from the scene with
void MainWindow::actualizar(){
for(auto &ast : v_asteroides){
if(ast->destruir()){
mundo->removeItem(ast);
v_asteroides.erase(std::remove(v_asteroides.begin(),v_asteroides.end(),ast),v_asteroides.end());
sonido->stop();
sonido->setMedia(QUrl("qrc:/multimedia/explosion1.mp3"));
sonido->play();
//std::cout << "eliminado" <<std::endl;
}
}
//std::cout << "tamaño : " <<v_asteroides.size() << std::endl;
mundo->advance();
mundo->update();}
however the object that is supposed to be removed from the screen remains there (still) without disappearing.